2016-09-27 3 views
0

내 문제는 암호가 암호 확인과 일치하지 않을 때 툴팁이 텍스트 필드에 나타나길 원합니다.암호 일치 도구 설명이 작동하지 않습니다.

다음은 툴팁에 대한 코드입니다. 이 문제를 해결하기 위해 내가 도움이 필요

<input type="password" class="form-control" id="Password" tabindex=7 name="Password" placeholder="Password" required="true" > 

<input type="password" class="form-control" id="ConfirmPassword" tabindex=8 name="ConfirmPassword" placeholder="Confirm Password" required="true"> 

: 다른이 작동하지만 암호의 일치 여기

function validateContact() { 
    var valid = true; 
    $("#container input[required=true], #container textarea[required=true]").each(function(){ 
    $(this).removeClass('invalid'); 
    $(this).attr('title',''); 
    if(!$(this).val()){ 
     $(this).addClass('invalid'); 
     $(this).attr('title','This field is required'); 
     valid = false; 
    } 
    if($(this).attr("type")=="email" && !$(this).val().match(/^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/)){ 
     $(this).addClass('invalid'); 
     $(this).attr('title','Enter valid email'); 
     valid = false; 
    } 

// for password match 
     if ($("#Password").val() != $("#ConfirmPassword").val()) {  

      $(this).addClass('invalid'); 
      $(this).attr('title','Password does not Match'); 
      valid = false; 
    } 
// end of password match 

    }); 
    return valid; 
} 

    $(function() { 
    $(document).tooltip({ 
    position: {my: "left top", at: "right top"}, 
    items: "input[required=true], textarea[required=true]", 
     content: function() { return $(this).attr("title"); } 
    }); 
    }); 

을하지 않는 것은 내 양식 코드입니다.

+1

경우 ($ ("# 암호 "). 발() == $ 시도 #ConfirmPassword ") .val()) - == 대신 =!가 아니어야합니까? – Danmoreng

+0

그것의 작동하지 않습니다 .. 나는 그것을 바꿉니다. :(페이지가로드되지만 데이터가 삽입되지 않습니다. –

+0

코드를 디버깅하려고 했습니까? 내 말은, 여기에는 여러 가지 가능성이 있습니다 ... – Javier

답변

0

ValidateContract 함수 안에 리스너가 있습니까? 어디에서 불러?

"(ID를 통해 입력에 직접 수신기를 넣어 ... 툴팁 쇼 변경을 console.log/메시지

$(document).on('keyup', '#ConfirmPassword', function(){ 
    if ($("#Password").val() == $(this).val()) 
     console.log("pass are equal"); 
    else 
     console.log("pass are not equal D:") 
}); 
+0

'# ConfirmPassword'와'# Password' 둘 다에 실제로 청취자가 필요합니다. 내 암호는 "blahblahblah"그런 다음 "blahblah"를 확인합니다 - 잠시만 기다리십시오. 마지막에'x'를 입력하십시오 - ConfirmPassword "blahblahblahx"에서 계속 입력하고 암호는 일치하지 않지만 암호로 돌아가서 마지막에 'x'를 붙이면 이제는 일치하지만 '# Password'에 청취자가 없으면 그것을 발견하지 못합니다. 어떤 경우에도'.on (변경, ...) '을 확인합니다. –

+0

시간 ... 질문의 해당 코드가 예상대로 작동하지 않으면 제안 할 수 없습니다. 다른 목적을 위해 더 많은 코드를 추가하려면 ... –

+0

사실, 나는 생각하기에 큰 소리로 생각하고있었습니다. –

관련 문제