Home > Backend Development > PHP Tutorial > PHP有关问题请问

PHP有关问题请问

WBOY
Release: 2016-06-13 12:18:38
Original
947 people have browsed it

PHP问题请教


* 联系电话: 
 

我想添加一个控制手机号为11位的提示框,应该怎么做?
非常感谢
------解决思路----------------------
用js 控制 每次输入的时候去判断下
------解决思路----------------------
$('input[name=user_phone]').blur(function(){
        var iphone = $(this).val();
        if(iphone.length != 11 ){
             $('#user_phone_show').html('请输入11位手机号');
        }
 })
------解决思路----------------------
可以直接用这个框
首先给你的的;"> 表单控件添加一个事件

 下面是js 需要jquery
function checkPhone(){
  var reg = /^1[345678]\d{9}$/;
  var phone = $(".inputall input150").val();
  if(phone.length       $("#user_phone_show").html("太短");
  }else if(reg.test(phone) == false) {
       $("#user_phone_show").html("格式不正确");
  }else{
       $("#user_phone_show").html("");
  }
}
------解决思路----------------------
電話號碼為11位數字。
<br />  <tr><br />	<td style="text-align:right;"><span class="cred1">*</span> 联系电话: </td><br />	<td style="text-align:left;"><input type="text" id="user_phone" name="user_phone" onblur="check_phone()" value="" class="inputall input150"> <span id="user_phone_show"></span></td><br />  </tr><br />  <script type="text/javascript"><br />	function check_phone(){<br />		var s = document.getElementById("user_phone").value;<br />		var pattern = new RegExp("^\\d{11}$");<br />		if(!pattern.test(s)){<br />		    document.getElementById("user_phone_show").innerHTML = '联系电话輸入不正確';<br />		}else{<br />		    document.getElementById("user_phone_show").innerHTML = '';<br />		}<br />	}<br />  </script><br /><br />
Copy after login

------解决思路----------------------
借鉴4楼大神的代码,进行了下正则优化
<tr><br />	<td style="text-align:right;"><span class="cred1">*</span> 联系电话: </td><br />	<td style="text-align:left;"><input type="text" id="user_phone" name="user_phone" onblur="check_phone()" value="" class="inputall input150"> <span id="user_phone_show"></span></td><br />  </tr><br />  <script type="text/javascript"><br />	function check_phone(){<br />		var s = document.getElementById("user_phone").value;<br />		var pattern = new RegExp("^1[3<br><font color='#FF8000'>------解决思路----------------------</font><br>5<br><font color='#FF8000'>------解决思路----------------------</font><br>7<br><font color='#FF8000'>------解决思路----------------------</font><br>8<br><font color='#FF8000'>------解决思路----------------------</font><br>][0-9]{9}$");<br />		if(!pattern.test(s)){<br />		    document.getElementById("user_phone_show").innerHTML = '手机号输入不正确';<br />		}else{<br />		    document.getElementById("user_phone_show").innerHTML = '正确';<br />		}<br />	}<br />  </script>
Copy after login

------解决思路----------------------
tp的自动验证,
验证条件
array('tel',"^(130<br><font color='#FF8000'>------解决思路----------------------</font><br>131<br><font color='#FF8000'>------解决思路----------------------</font><br>132<br><font color='#FF8000'>------解决思路----------------------</font><br>133<br><font color='#FF8000'>------解决思路----------------------</font><br>134<br><font color='#FF8000'>------解决思路----------------------</font><br>135<br><font color='#FF8000'>------解决思路----------------------</font><br>136<br><font color='#FF8000'>------解决思路----------------------</font><br>137<br><font color='#FF8000'>------解决思路----------------------</font><br>138<br><font color='#FF8000'>------解决思路----------------------</font><br>139)\d{8}$",'手机格式不正确'),
Copy after login

参考
http://document.thinkphp.cn/manual_3_2.html#auto_validate
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template