我有這個功能檢查的文本字段是否包含數字而已,如果有信件在這個領域,然後錯誤應該顯示檢查文本字段是否只包含數字和必須是11位
//Tel Validate
function is_valid_tel() {
$this = $("#inputTel");
var pattern = new RegExp("^[0-9]*$");
if(pattern.test($this.val())){ // valid
if ($this.closest(".control-group").hasClass("error"))
$this.closest(".control-group").removeClass("error");
$this.siblings(".help-inline").css("display", "none");
return true;
} else { // error
if (!$this.closest(".control-group").hasClass("error"))
$this.closest(".control-group").addClass("error");
$this.siblings(".help-inline").css("display", "block");
return false;
}
}
當我在文本字段中輸入字母,我不會拋出任何錯誤。我的jQuery/JavaScript是有限的,但我認爲這至少會工作?因爲reg exp會檢查0-9之間的數字。我還想來檢查,如果輸入號碼,然後它匹配11位
任何幫助表示讚賞感謝
感謝擴展答案,但仍然無法正常工作,也許在其他地方的問題?儘管我所有的其他功能都是從這個功能中分離出來。 – Richlewis
所有工作,發佈我的結論,再次感謝 – Richlewis