質問

Im trying to find, in my javascript, if i can identify in a variable if a "@" sign is present in the variable.

 e = _("email").value;

 if(e don't contain "@"){
     alert("Dosnt contain @");
 }
 else {
     alert("email has @");
 }

正しい解決策はありません

他のヒント

You can use regular expressions to validate an email. Would be more easy to maintain and manage.

$('form input[name="email"]').blur(function () {
    var email = $(this).val();
    var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/igm;
    if (re.test(email)) {
        $('.msg').hide();
        $('.success').show();
    } else {
    $('.msg').hide();
    $('.error').show();
    }
});

LIVE EXAMPLE

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top