简体   繁体   中英

For E-Mail validation this code not working can i know the reason

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;

}

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-\\._]

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!');
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM