473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need help understanding regular expression

Joe
Hi,

I have been using a regular expression that I don’t uite understand to
filter the valid email address. My regular expression is as follows:

<asp:RegularExpressionValidator id="valValidEmail"
runat="server"
ControlToValidate="txtEmail"

ValidationExpression="^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"
ErrorMessage="Invalid Email address."
Display="None">
</asp:RegularExpressionValidator>

Can someone explain me why the email address jo*******@Z-5com.com is
considered an invalid email address?

Also can someone explain me what the above regular expression means?

Thanks,

Joe

Nov 19 '05 #1
3 2269
Hi Joe,

For an excellen regular expression resource pretaining to ASP.NET check
out http://RegExLib.com.

Try the following regular expression to help with e-mail address
validation:
http://regexlib.com/REDetails.aspx?regexp_id=284

Tod Birdsall, MCSD for .Net
http://tod1d.blogspot.com

Nov 19 '05 #2
the expression was written to be called with ignore case, but I'm not sure
you can pass the /i modifier to client script, so the capital Z fails.

explaining how complex regex expression works, is a bit beyond a newgroup
question. read about them, then ask about the part(s) you don't understand.
expect to spend several hours studying on it.

-- bruce (sqlwork.com)
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
Hi,

I have been using a regular expression that I don't uite understand to
filter the valid email address. My regular expression is as follows:

<asp:RegularExpressionValidator id="valValidEmail"
runat="server"
ControlToValidate="txtEmail"

ValidationExpression="^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"
ErrorMessage="Invalid Email address."
Display="None">
</asp:RegularExpressionValidator>

Can someone explain me why the email address jo*******@Z-5com.com is
considered an invalid email address?

Also can someone explain me what the above regular expression means?

Thanks,

Joe

Nov 19 '05 #3
Hi Joe,
Can someone explain me why the email address jo*******@Z-5com.com is
considered an invalid email address?
Thats easy. The regex doesn't match capital letter. The regex says that after
the @ symbol the following may occur :
([a-z0-9-]+)
With some imagination you can see what is ment by a-z. It means a or b or
c or d ... or z But it doesn't mean any capital.
If you change the above to
([a-zA-Z0-9-]+)
The email "oe.green@Z-5com" will match now.

But dont expect the improved regex to match every valid email now. The rules
that make up a valid email are complex and so is a corresponding regex that
tries to match every possible variation.
You can try regexes you find on the net or at http://RegExLib.com and see
if it does match your newly discovered anomaly.

But if you don't understand regexes and only copy paste them you will now
for sure have cases in wich the new regex doesnt match where the old regex
did.

The best way is to learn the essentials of regexes so you can diagones the
problem and make a small correction to the regex isntead of pasting a completly
new one.

Here are some resources if you have the time and intrest :

The short intro http://www.regular-expressions.info/
The tool http://www.regexbuddy.com/screen.html
The book Mastering Regular Expressions by Jeffrey Friedl (http://regex.info/
Also can someone explain me what the above regular expression means?
Thats harder because a regex conveys much information in a short line. In
general that regex says
- only match emails that are alone one a line with no surrounding text (^
and $ take care of this)
- Match letters and digits and - followed by a point and than some more
of the same
- match the @
- Match letters and digits and - followed by a point and than some more
of the same
- end with a text section thats 2 to 4 characters in lenght (.com is ok .commercial
is not)

If you read the intro at http://www.regular-expressions.info/ most of the
more subtle details will become apparant I hope.

Let me know if you have any more questions..

Cheers,
Tom Pester
Hi,

I have been using a regular expression that I don't uite understand to
filter the valid email address. My regular expression is as follows:

<asp:RegularExpressionValidator id="valValidEmail"
runat="server"
ControlToValidate="txtEmail"
ValidationExpression="^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a
-z0-9-]+)*(\.[a-z]{2,4})$"
ErrorMessage="Invalid Email address."
Display="None">
</asp:RegularExpressionValidator>
Can someone explain me why the email address jo*******@Z-5com.com is
considered an invalid email address?

Also can someone explain me what the above regular expression means?

Thanks,

Joe

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joh | last post by:
Hello, (sorry long) i think i have missed something in the code below, i would like to design some kind of detector with python, but i feel totally in a no way now and need some advices to...
2
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
3
by: moondaddy | last post by:
I need to rename file names with a specific naming convention which includes adding a SKU number at the end of the file name and I would like to use a regular expression to do this, but I don't...
18
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: Lucky | last post by:
hi guys, i'm practising regular expression. i've got one string and i want it to split in groups. i was trying to make one regular expression but i didn't successed. please help me guys. i'm...
14
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.