Skip to content Skip to sidebar Skip to footer

Regex For Email Validation (minimum Characters)

How to write a regular expression for email validation in javascript so that,characters before '@' should have minimum length of 5(those characters can be any between A-Z/a-z/0-9_-

Solution 1:

To answer your question the regex would be

/^[\w-]{5,}@.*$/

Solution 2:

I always use this site for regular expressions

http://regexlib.com/Search.aspx?k=email

and to use it with JavaScript

function emailValidation()
{
var emailRegEx =/^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._-])?([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/

if (document.testForm.textBox.value.search(emailRegEx )==-1) //if match failed
{
alert("invalid Email!!!");
}
else
{
alert("valid Email.");
}
}

Post a Comment for "Regex For Email Validation (minimum Characters)"