Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email regular expressions

Status
Not open for further replies.

newbby

Programmer
Mar 16, 2004
36
US
Hi,
How can I validate an email in this format using regular expressions: alphanumeric@something.com OR alpha.alpha@something.com. I am only certain about the @something.com, the prefix can change. Thanks in advance.
 
This is the email regex that I use (I didn't write it and I can't remember where I got it):
Code:
function checkForEmail(str) {
   return ((/\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}/).test(str))
}

-kaht

banghead.gif
 
TheStr="EmailId"
if(!TheStr.match(/^[a-z]([\-_\.]?[a-z0-9]+)*@([a-z0-9]+([\-_][a-z0-9]+)*\.)+[a-z]{2,}$/ig))
{
alert("Invalid email.")
}

Rules:
allows _,-,.
last characters must be alphabets (atleast 2 in length)....

Known is handfull, Unknown is worldfull
 
Hi All,
Thanks for all the help. But I guess I might have miscommunicated. I know for sure that the suffix in the email "@something.com" will be same. What I am not sure about is the prefix for the email can be either alphanumerics or alpha.alpha like in "alphanumerics@something.com" or "alpha.alpha@something.com". I need to validate the prefix using regular expression. The code provided by you actually checks the entire string in the email. Thanks
 
So why not take the portion of our regex's before the @ symbol and add the rest of your @something.com to it? It'd be the same thing.

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top