JavaScript 유효성 검사 및 학습에 익숙하지 않습니다. 양식 유효성을 검사하려고하지만 조건에 문제가 있습니다.조건에 따른 유효성 검사 문제
제 양식에는 이름과 제출 버튼이 하나 인 필드가 있습니다.
내가 시도하고있다 : 사용자가 클릭 버튼과 텍스트 상자가 비어 제출 정규식에 의해 허용되지 않은 사용자 입력 값이 alert('Please enter only letters no special character allowed.');
을 줄 경우 alert('Please enter your First Name.')
을 제공하지만 다음의 제품에
경우 매번 처음 경고하고 있습니다. 뭐가 잘못 됐는지 이해가 안돼.
내 코드 :
jQuery('#send').click(function() {
var reg_first_name = /^[A-Za-z ]{3,20}$/;
var first_name = jQuery('#sa_first_name').val();
if(first_name.length > 0){
alert('Please enter your First Name.');
document.getElementById("sa_first_name").focus();
return false;
}
if (!reg_first_name.test(first_name)) {
alert('Please enter only letters no special character allowed.');
document.getElementById("sa_first_name").focus();
return false;
}
return false;
});
당신은 나를 인도 할 수 있습니까? 당신이 다음 조건을 사용자가 first_name.length > 0
항상 true가됩니다 이름을 입력 경우
if(first_name.trim().length == 0){
VAR의 reg_first_name을 회피 = "/^[A-ZA-Z] {3,20} $ /"처럼 확인할 수있다; if (first_name.length == 0) { –