Link to home
Start Free TrialLog in
Avatar of Meenalu
Meenalu

asked on

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

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
Avatar of Stephan
Stephan
Flag of Netherlands image

\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
Avatar of Meenalu
Meenalu

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Stephan
Stephan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Meenalu

ASKER

Thank you so much, stephanonline.
-Meenalu