|
通過js正則驗(yàn)證手機(jī)號(hào)碼的有效性,方法如下: 驗(yàn)證130-139,150-159,180-189號(hào)碼段的手機(jī)號(hào)碼
- <script type="text/javascript">
- var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
- if(!myreg.test($("#phone").val()))
- {
- alert('請(qǐng)輸入有效的手機(jī)號(hào)碼!');
- return false;
- }
- </script>
以上代碼是在jquery下調(diào)試的。不需要jquery的代碼
- function validatemobile(mobile)
- {
- if(mobile.length==0)
- {
- alert('請(qǐng)輸入手機(jī)號(hào)碼!');
- document.form1.mobile.focus();
- return false;
- }
- if(mobile.length!=11)
- {
- alert('請(qǐng)輸入有效的手機(jī)號(hào)碼!');
- document.form1.mobile.focus();
- return false;
- }
-
- var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
- if(!myreg.test(mobile))
- {
- alert('請(qǐng)輸入有效的手機(jī)號(hào)碼!');
- document.form1.mobile.focus();
- return false;
- }
- }
轉(zhuǎn)載請(qǐng)注明:代碼家園 ? js正則驗(yàn)證手機(jī)號(hào)碼有效性
|