Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-04-04
4
Medium Priority
?
355 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

971 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