...

View Full Version : How do I include a ‘dot’ and a ‘hyphen’ in the name section of an email address with



Ade B
07-21-2010, 11:15 AM
This is the regular expression I currently have
/^(\w+|\w+.\w+)@(\w+|\w+\-\w+)\.(\w{2,3}|\w{2,3}\.\w{2,3})$/; the script dates from about 2006. The script is ok for emails that just contain a ‘dot’ before the @, as in:
joe.bloggs@home.com

What needs to be changed in the above script to allow both these types of email?
joe.bloggs@home.com and
joe.bloggs-smith@home.com

Any help greatly appreciated.

Dormilich
07-21-2010, 12:53 PM
use a character class

(\w+(?:[-.]\w+)*)
ok, that allows more than exactly one . or -, though

Ade B
07-21-2010, 04:45 PM
Thank you Dormilich, your answer was perfect. I have tested the form and it
now works as I wanted - Much appreciated



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum