Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Validate EMail with RegExp...

Thread view: 
Dag Sunde - 03 Nov 2005 10:24 GMT
My understanding of regular expressions is rudimentary,
at best.

I have this RegExp to to a very simple validation of an
email-address, but it turns out that it refuses to
accept mail-addresses with hypens in them.

Van anybody please help me adjust it so it will accept
addresses like dag-sunde@test-domain.net too?

Here's what got:

function validateEmail(eMail) {
return /^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$/.test(eMail);
}

TIA...

Signature

Dag.

Work is the curse of the drinking classes
                          -- Oscar Wilde

Dag Sunde - 03 Nov 2005 10:38 GMT
> My understanding of regular expressions is rudimentary,
> at best.
[quoted text clipped - 11 lines]
> return /^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$/.test(eMail);
> }

Ooops!

Sorry, I really meant to post this to c.l.javascript, not java...
(But if anyone know the answer...)

Signature

Dag.

carlos@gkpwdun.com - 03 Nov 2005 11:41 GMT
>> My understanding of regular expressions is rudimentary,
>> at best.
[quoted text clipped - 11 lines]
>> return /^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$/.test(eMail);
>> }

return  /^[\w.+-]+@[\w.+-]+\.[\w]{2,7}/.test(eMail);
Roedy Green - 03 Nov 2005 12:19 GMT
> return /^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$/.test(eMail);

see http://mindprod.com/jgloss/regex.html. have a look at what \w is
short for, and use that expansion slightly modified.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Dag Sunde - 03 Nov 2005 13:25 GMT
> My understanding of regular expressions is rudimentary,
> at best.
[quoted text clipped - 5 lines]
> Van anybody please help me adjust it so it will accept
> addresses like dag-sunde@test-domain.net too?

Thank you all!

I ended up with thisone (wraps):

function validateEmail(eMail) {
return
/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(eMail);
}

Signature

Dag.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.