Solved

Regular expression to validate trailing and leading spaces - ASP.NET

Posted on 2012-04-04
4
345 Views
Last Modified: 2012-04-07
Hello,
i am using this regex

ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(?:kellogg\.northwestern\.edu|tuck\.dartmouth\.edu|georgetown\.edu))"


how to validate leading and trailing spaces (before and after email address) also?

-meenalu
0
Comment
Question by:Meenalu
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Stephan
ID: 37809653
\s references to a space

You could use (\s*) when there is zero or more spaces
Or you can use (\s+) equals 1 or more spaces
0
 

Author Comment

by:Meenalu
ID: 37810717
Stephanonline,

should my validator be like this:

I have added (\s*)  after "^" and before we end the expression.  Is this correct.  Do i have to use two (\s*) .  please check and let me know if the expression is correct.

ValidationExpression="^(\s*) ([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(?:kellogg\.northwestern\.edu|tuck\.dartmouth\.edu|georgetown\.edu))(\s*) "


meenalu
0
 
LVL 16

Accepted Solution

by:
Stephan earned 500 total points
ID: 37810734
If you need to accept leading and trailing spaces, you can use the one you submitted.
0
 

Author Closing Comment

by:Meenalu
ID: 37819204
Thank you so much, stephanonline.
-Meenalu
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question