程式碼如下: 複製程式碼 程式碼如下: <BR>String.prototype.Trim = function() { <BR>var m = this.match(/^s*(S (s S )*)s*$/); <BR>return (m == null) ? "" : m[1]; <BR>} <BR>String.prototype.isMobile = function() { <BR>return (/^(?:13d|15[89])-?d{5 }(d{3}|*{3})$/.test(this.Trim())); <BR>} <BR>String.prototype.isTel = function() <BR>{ <BR>// "相容格式: 國家代碼(2到3位)-區號(2到3位)-電話號碼(7到8位)-分機號(3位)" <BR>//return (/^(([0 ]d{2,3}-)?(0d{2,3})-)?(d{7,8})(-(d{3,}))?$/.test(this.Trim() )); <BR>return (/^(([0 ]d{2,3}-)?(0d{2,3})-)(d{7,8})(-(d{3,} ))?$/.test(this.Trim())); <BR>} <BR>function chkForm() { <BR>with(document.form1){ <BR>if (tel.value.isMobile() ||tel.value.isTel()) { <BR>tel.value = tel.value.Trim(); <BR>alert("您的電話/手機號碼是:" tel.value); <BR>return true; <BR>} <BR>else { <BR>alert("請輸入正確的手機號碼或電話號碼 n例如:13916752109或0712-3614072"); <BR>tel.focus(); <BR>return false; <BR>} <BR>} <BR>} <BR>