Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 47
How to get a Powershell script to launch from Visual Studio 20 63
Asp response.write to clients 6 32
SSIS GUID Variable 2 30
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

685 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