Solved

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

Posted on 2012-04-04
4
342 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now