Validate EMail with RegExp...

D

Dag Sunde

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 (e-mail address removed) too?

Here's what got:

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


TIA...
 
D

Dag Sunde

Dag Sunde said:
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 (e-mail address removed) too?

Here's what got:

function validateEmail(eMail) {
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...)
 
C

carlos

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 (e-mail address removed) too?

Here's what got:

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

return /^[\w.+-]+@[\w.+-]+\.[\w]{2,7}/.test(eMail);
 
D

Dag Sunde

Dag Sunde said:
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 (e-mail address removed) 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);
}
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top