2017-12-23 2 views
0

.jsp 파일에 두 개의 입력 필드가 있는데 둘 다 동시에 볼 수 있습니다. phone1은 필수이며 의도 한대로 작동하고 있습니다 (형식을 따라 10 자까지 채워 져야 함). 그러나 phone2는 작동하지 않습니다. phone1과 동일한 규칙을 따르지 만 입력 필드에 무언가가 입력 된 경우에만 문제를 알리고 싶습니다.Spring JS - 입력 필드

ex. 문자 나 하나 개의 번호가 phone2을 체결 한 경우, 설정 요소 텍스트에 :

나는이 고정에 대해 어떻게 갈 것이라고

var phoneformat = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/; 

     //phone1="home phone" phone2="work phone" 

     if (phone1 == "" || phone1.length != 10 || !phone1.match(phoneformat)){ 
     document.getElementById("vHphone").innerHTML="*please enter a 10 digit number with no special characters"; 
     return false; 
    } else if (phone2 != "" && phone2.length < 10 || !phone2.match(phoneformat)){ 
     document.getElementById("vWphone").innerHTML="*please enter a 10 digit number with no special characters"; 
     return false; 

"* 특수 문자와 10 자리 숫자를 입력하십시오"?

+0

을 downvoted 그는이 할 수있는 OP는 자신의 질문에 많은 관련이없는 태그를 치고있는 것처럼 보인다 때문이다. – Synch

답변

0

오른쪽 phone2 != ""을 현재 or 연산자 오른쪽에 추가 할 수 있습니다. 그렇지 않으면 !phone2.match(phoneformat)에 대해서만 트리거됩니다.

else if (phone2 != "" && phone2.length < 10 || phone2 != "" && !phone2.match(phoneformat)) 

또는

else if(phone2 != ""){ 
    if(phone2.length < 10 || !phone2.match(phoneformat)){ 
    return false; 
    } 
}