양식을 제출하기 전에 Quebec 우편 번호를 확인하려고합니다. 다음 함수 (onBlur)는 문자를 대문자로 만들고 공백을 제거해야합니다. "else"이전의 모든 항목이 정상적으로 작동합니다.JS 유효성 검사에서 regexp, replace 및 ToUppercase 문제가 발생했습니다.
function back2(that){
if (that.value.length <=4) {
that.value = that.getAttribute("default");
that.setAttribute("class", "exemple");
} else {
if (that.getAttribute("id") == 'zip') {
that.setAttribute("value", that.value.replace(/\s/g, ""));
that.setAttribute("value", that.value.toUpperCase());
}
}
}
이 제품은 onSubmit 이벤트에 의해 트리거 양식 유효성 검사 코드의 일부입니다
if (f.value != "^G//d//D//d//D//d$" ||
f.value != "^H//d//D//d//D//d$" ||
f.value != "^J//d//D//d//D//d$" ||
f.value != "^K1//D//d//D//d$" ||
f.length !=6) {
alert("Veuillez mettre un code postal valide du Québec, merci.");
return false;
}
return true;
}
및 HTML 코드 :
<td>Code Postal</td>
<td><input name="zip" type="text"
id="zip" value="J0B4M1" size="35"
class="exemple" onfocus="clean(this)"
onblur="back2(this)" default="J0B4M1"></td>
JS 코드의 두 부분에서 문제가 아무것도 때문에 필드 상자를 변경하면 우편 번호에 공백이 있고 소문자로 표시됩니다. 또한 우편 번호 형식이 올바른 경우에도 알림이 표시됩니다. 도움!
oops ... 전달 슬래시는 백 슬래시 여야합니다. – Ishikawa
@RobG 감사합니다! – Ishikawa