Regular Expressions?

A

Arpan

Using RegularExpression, the following TextBox ensures that users enter
a valid e-mail address which has a '@' & ends with ".com":

<asp:TextBox id="txtEMail" runat="server"/>
<asp:RegularExpressionValidator ControlToValidate="txtEMail"
ValidationExpression="\w+\@\w+\.com" ErrorMessage="Invalid Email ID"
runat="server"/>

I have gone through many articles on RegularExpressions available on
the Net but have never come across the "w" RegularExpression character.
I know what the other RegularExpression characters used above do but
what is this "w"? What does "w" mean here"? Does it signify a word
(which can be just about anything)?

Similarly, consider the following RegularExpression:

href\\s*=\\s*(\"([^\"]*)\"|(\\S+))

The above RegularExpression means 'href' followed by zero or more white
spaces (\s*), then by '=', then by zero or more white spaces again.
This is then followed by a double quote (\"), then by zero or more
occurences of anything that's not a double quote ([^\"]*), followed by
a double quote 'or' one or more non-white space characters (\S+).

Like the characters "w", "s", "S", are there any other letters from 'a'
to 'z' (or from 'A' to 'Z') that have a special meaning in
RegularExpressions? If yes, what are they?

Thanks,

Arpan
 
H

Hans Kesting

Using RegularExpression, the following TextBox ensures that users enter
a valid e-mail address which has a '@' & ends with ".com":

<asp:TextBox id="txtEMail" runat="server"/>
<asp:RegularExpressionValidator ControlToValidate="txtEMail"
ValidationExpression="\w+\@\w+\.com" ErrorMessage="Invalid Email ID"
runat="server"/>

Just some remarks:
- there are e-mail addresses that end in something other than ".com"
(such as two-letter country codes). Do you *really* want to limit to
..com addresses?
- the "\w+\.com" will only accept "company.com", not
"subdomain.company.com". Is that *really* a requirement?

Hans Kesting
 
K

Kevin Spencer

Yes, in fact, the rules regarding valid SMTP email addresses are quite
complex, if you really want to validate an email address. However, it should
also be noted that a valid email address is not necessarily a correct email
address. That is, it may or may not be spelled correctly, and may or may not
point to a valid email account. So, the validation for an email address
varies according to the requirements.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
topweb3twitterchannels

Latest Threads

Top