jsp如何验证用户信息

 时间:2024-10-13 16:12:31

1、首先写一个form表单,里面的信息如下:<form method="post" id="form&鳎溻趄酃quot; action="xxx" onsubmi="return check_form()">用户名字:<input type="text" name="username" value=""><br>用户密码:<input type="password" name="password1" value=""><br>再次确认密码:<input type="text" name="password2" value=""><br>用户手机号:<input type="text" name="tel" value=""><br>用户身份证:<input type="text" name="idno" value=""><br>用户邮箱:<input type="text" name="mail" value=""><br><input type="submit" value="提交"><input type="reset" value="重置"></form>

jsp如何验证用户信息

2、首先是不为空的撰颧幌汪验证((用到了js技术):<script>functioncheck_form(){//获得表单的id var f=document.getElementById("form");//判断所有表单都不为空if(f.username.value==null||f.password1.value||f.password2.value||f.tel.value==null||f.idno.value==null||f.mail.value==null){alert("不可以有空值!");return false;}}</script>为方便大家看 我把这些验证 从一个方法里面分出来了!

jsp如何验证用户信息

3、判断身份证格式是否正确(用到了js里面的正则表达式)<script>functioncheck_form(){//获得表单的id var f=document.getElementById("form");//判断身份证的格式if(!/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(f.idno.value)){ alert("身份证号格式错误"); return false; }}</script>

jsp如何验证用户信息

4、判断用户手机号的格式是否正确:<script>functioncheck_form(){//获得表单的id var f=document.getElementById("form");//判断手机号码的格式if(!/^1[3458]\d{9}$/.test(f.tel.value)){ alert('手机号码格式不正确'); return false; }}</script>

jsp如何验证用户信息

5、//判断用户两次输入的密码是否一致<script>functioncheck_form(){//获得表单的id var f=document.getElementById("form");//判断两次输入的密码是否一致if(f.password1.value!=f.password2.value){ alert("两次输入的密码不一样,请重新输入!"); return false; }}</script>

jsp如何验证用户信息

6、//判断邮箱输入格式是否正确<script>functioncheck_form(){//获得表单的id var f=document.getElementById("form");var email=f.mail.value;if(email.search("^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))//邮箱验证正则表达式{return true;}else{return false}}</script>

jsp如何验证用户信息
  • 如何快速计算出给定数组中的最小值
  • AxureRP如何设置单选按钮唯一选中
  • 如何用MATLAB进行高通FIR滤波器仿真
  • Starting Tomcat Server at localhost failed
  • jquery如何给a标签添加下划线
  • 热门搜索
    文明城市手抄报 劳动节手抄报简单好画 天下国家手抄报 天安城门手抄报 少先队手抄报 五年级数学手抄报 校园手抄报模板 科技创新手抄报 我的中国梦手抄报 语文手抄报内容