473,287 Members | 1,395 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,287 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 2257
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.