好的,我有一個驗證腳本,用於檢查表單上的所有內容 - 但它會將電話號碼字段標記爲錯誤,而不管內容是什麼。我嘗試了幾種不同的方法,我無法弄清楚我做錯了什麼。表單驗證問題(電話號碼)
,用於驗證是腳本的一部分...
if (testPattern(phone1, /^\d{3}$/)== false) { // checking phone length
valid = false;
}
if (testPattern(phone2, /^\d{3}$/)== false) {
valid = false;
}
if (testPattern(phone3, /^\d{4}$/)== false) {
valid = false;
}
的功能代碼...
function testPattern(field, reg2) {
var trueOrfalse = reg2.test(field)
if (trueOrfalse == false) {
field.style.backgroundColor="yellow"; // if false, change colors and return false
field.style.color="red";
return false;
}
else {
field.style.backgroundColor="white"; // if true, change colors and return true
field.style.color="black";
return true;
}
}
+1用於指定您應該在其含義之後命名變量。 – Cam 2010-03-07 02:11:46