Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Need help understanding regular expression

Reply
Thread Tools

Need help understanding regular expression

 
 
=?Utf-8?B?Sm9l?=
Guest
Posts: n/a
 
      08-02-2005
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 http://www.velocityreviews.com/forums/(E-Mail Removed) is
considered an invalid email address?

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

Thanks,

Joe

 
Reply With Quote
 
 
 
 
Tod Birdsall
Guest
Posts: n/a
 
      08-03-2005
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

 
Reply With Quote
 
 
 
 
Bruce Barker
Guest
Posts: n/a
 
      08-03-2005
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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 (E-Mail Removed) is
> considered an invalid email address?
>
> Also can someone explain me what the above regular expression means?
>
> Thanks,
>
> Joe
>



 
Reply With Quote
 
Tom.PesterDELETETHISSS@pandora.be
Guest
Posts: n/a
 
      08-03-2005
Hi Joe,

> Can someone explain me why the email address (E-Mail Removed) 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 (E-Mail Removed) is
> considered an invalid email address?
>
> Also can someone explain me what the above regular expression means?
>
> Thanks,
>
> Joe
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Need help understanding regular expression Joe ASP General 2 08-03-2005 12:47 PM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments