February 26th, 2009, 11:09 AM
Email Regular expression
I am using following regular expression to validate email addresses but somehow it is not validating emails for hyphen or dashes (-).
this email is not valid with following regex: email-email @ email .gov (put spaces as forum blocks email addresses.)
var emailpattern=new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)");
Any idea what am i missing even when included hyphen.
Any help would be really appreciated.
February 26th, 2009, 11:37 AM
You may be implementing this with JS, but it's more of a general RegEx
question, I think.
I've moved it to the RegEx forum where it should get some attention.
If you have trouble implementing the final solution in your JS, just pop
back into the JS forum and someone should be able to help.
February 26th, 2009, 11:38 AM
You might also find that if you search this forum, someone might have
had a similar problem and posted a solution.
February 26th, 2009, 04:04 PM
Try this expression on for size:
Also, that expression you posted DID match email@example.com for me in PHP. No edits aside from the escapes on your backslashes. Are you sure you're doing them right?
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
February 26th, 2009, 06:08 PM
Just a warning, the real parsing of email addresses, as specified by RFC822, is really ugly. While its probably possible to do it all with a regex, I've never seen one that is perfect.
But a quick search will get one that is good enough for real world use.
February 26th, 2009, 06:35 PM
There is a regular expression to validate any RFC 822 compliant address, but the actual expression is over 1 page long and is mind-bogglingly complex.
Comments on this post
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
February 26th, 2009, 06:57 PM
I didn't know it existed. Thanks.
Originally Posted by Scorpions4ever
I can believe on the mind-boggling part
March 2nd, 2009, 04:48 PM
Being able to use "+" in my addresses for the purpose sorting messages is useful for me. (Some people call it "plus addressing".) Unfortunately many sites don't allow addresses like that.
Comments on this post