문제

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