2016-10-03 2 views
-1

이름, 전화 번호, 성, 이메일을 확인하고 싶지만 제출하고 싶을 때 작동하지 않습니다 .. 내 표정을 바꾸려고했지만 아무 것도하지 않았습니다.정규 표현식에서 왜 제대로 작동하지 않습니까?

$(document).ready(function(){ 
     $('#ok').on('click',function(){ 
      var name = $('#txtNombre').val(); 
      var surname = $('#txtApellido').val(); 
      var email = $('#txtCorreo').val(); 
      var phone = $('#txtTelefono').lengh; 
      if(name == null || name.length == 0 || /^[a-zA-Z ]+$/.test(name)){ 
       $("#txtNombre").css('border-color','red'); 
      }else{ 
      $("#txtNombre").css('border-color',''); 
      } 
      if(surname == null || surname.length == 0 || /^[a-zA-Z ]+$/.test(surname)){ 
       $("#txtApellido").css('border-color','red'); 
      }else{ 
      $("#txtApellido").css('border-color',''); 
      } 
      if(email == null || email.length == 0 || /^[a-zA-Z0-9._-][email protected][A-Za-z0-9]+.(com|com.mx|es|edu.mx)$/.test(email)){ 
       $("#txtCorreo").css('border-color','red'); 
      }else{ 
      $("#txtCorreo").css('border-color',''); 
      } 
      if(phone == null || phone.length == 0 || /^[0-9]+$/.test(phone)){ 
       $("#txtTelefono").css('border-color','red'); 
      }else{ 
      $("#txtTelefono").css('border-color',''); 
      } 
     }); 
     $('#cancel').on('click',function(){ 
      $('#txtNombre, #txtApellido, #txtCorreo, #txtTelefono').val(''); 
      $('#txtNombre, #txtApellido, #txtCorreo, #txtTelefono').css('border-color',''); 
     }); 
    }); 
+1

는 "작동하지 않는다"는 조금 모호합니다. 어떤 행동을 기대하고 있으며 어떤 행동을하고 있습니까? 질문을 업데이트하십시오. –

답변

관련 문제