Reputation: 1331
I am using custom[email] rule for email validation in Jquery Validation Engine. What I want is, I want regex that validates email with blank value also. If value is blank then also it should show error message. I dont want to use required rule.
Here is the custom rule given in Jquery Validation Engine
"email": {
// HTML5 compatible email regex ( http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html# e-mail-state-%28type=email%29 )
"regex": /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
"alertText": "* Invalid email address"
}
Please help me out.
Upvotes: 0
Views: 370
Reputation: 1
function checkEmail(email) {
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
if (!reg1.test(email) && reg2.test(email)) {
return true;
}
else {
return false;
}
}
Upvotes: 0
Reputation: 135227
This should work
^([^@]+@[^@]+)?$
It will validate
@
@
@
Upvotes: 1
Reputation: 4876
try this here is the fiddle
var emailReg = /^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/;
Upvotes: 0