jquery验证手机号是否正确实例讲解

前端之家收集整理的这篇文章主要介绍了jquery验证手机号是否正确实例讲解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如果要做手机号的验证,那么我们需要知道手机号码的号段。 支持号段:134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188

支持号段:130 131 132 145 155 156 176 186

支持号段:133 153 177 180 181 189 //移动运营商:170

移动:

2G号段(GSM):134-139、150、151、152、158-159; 3G号段(TD-SCDMA):157、187、188、147.

联通:

2G号段(GSM):130-132、155-156; 3G号段(WCDMA):185、186.

电信:

2G号段(CDMA):133、153; 3G号段(CDMA2000):180、189. 可以写出一个正则表达式:var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/; 首先引入一个JQuery框架:

校验手机号的函数

提示错误效果 //jQuery("#phoneDiv").removeClass().addClass("ui-form-item has-error"); //jQuery("#phoneP").html(""); //jQuery("#phoneP").html(""+message); //jQuery("#phone").focus(); }else{ //提示正确效果 //jQuery("#phoneDiv").removeClass().addClass("ui-form-item has-success"); //jQuery("#phoneP").html(""); //jQuery("#phoneP").html("该手机号码可用"); } return flag; }

发送请求给后台

java后端进行校验:

Map<String,Object> map = new HashMap<String,Object>(); try { String phone = request.getParameter("phone"); String status = "0"; //写<a href="https://www.jb51.cc/tag/chaxun/" target="_blank" class="keywords">查询</a>逻辑,查出有的话,那么<a href="https://www.jb51.cc/tag/biaoji/" target="_blank" class="keywords">标记</a>为1,否则<a href="https://www.jb51.cc/tag/biaoji/" target="_blank" class="keywords">标记</a>为0 //UserCellphoneAuth userCellphoneAuth = userService.findUserCellphoneAuthByPhone(phone); //if(userCellphoneAuth!=null){ // status = "1"; //} map.put("status",status); String data = JSONObject.fromObject(map).toString(); response.getWriter().print(data); response.getWriter().flush(); response.getWriter().close(); } catch (Exception ex) { logger.error(ex.getMessage(),ex); }

}

以上就是本文的全部内容,教大家如何进行jquery验证手机号是否正确,利用正则表达式,大家可以动手试一试。

原文链接:https://www.f2er.com/jquery/51684.html

猜你在找的jQuery相关文章