Reputation:
Check this. At email field
its not accepting even single key stroke also. Upto my knowledge mistake there at AllowRegex
variable its unable to validate what i enter in email field in form..
function mailonly(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
var AllowRegex = /^[\ba-zA-Z0-9\s-._ ]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
if (AllowRegex.test(character))
return true;
return false;
}
Upvotes: 2
Views: 65
Reputation: 61
AllowRegex check complete Email-Id not single character and you are checking text on every keypress.
check this it will help you check it.
another example is jsfiddle.net/bKT9W/2/.
function validateEmail() {
var validEmail = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if (validEmail.test($('#user_email').val())) {
$('.masked-check').fadeIn(300);
$('#status').html('Valid Email!');
}
else {
$('.masked-check').fadeOut(300);
$('#status').html('INVALID Email!');
}
}
Upvotes: 0
Reputation: 15483
try to validate the email after the complete email address is written. I think you use onblur
for that.
Also I notices that you allowed \s
(white spaces) in the email which is not correct. You should use \S
(CAP) instead. which is opposite of \s
.
Also there should be a \
before the .
(DOT). /^[\ba-zA-Z0-9\S-\._]
Upvotes: 1