Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  Jsp  >  正文 jsp判断移动设备正则 js验证手机号码

jsp判断移动设备正则 js验证手机号码

发布时间:2015-09-30   编辑:www.jquerycn.cn
本文介绍了jsp验证手机号码的方法,jsp判断移动设置的正则实例,有需要的朋友参考学习下。

jsp文件名为 index.jsp,其实也可以使用过滤器来进行拦截,然后跳转到其他域名去。
 
完整代码
 

复制代码 代码示例:
<%@page import="java.util.regex.matcher"%>
<%@page import="java.util.regex.pattern"%>
<%@ page language="java" pageencoding="utf-8"%>
<%!
 
// \b 是单词边界(连着的两个(字母字符 与 非字母字符) 之间的逻辑上的间隔),
// 字符串在编译时会被转码一次,所以是 "\\b"
// \b 是单词内部逻辑间隔(连着的两个字母字符之间的逻辑上的间隔)
string phonereg = "\\b(ip(hone|od)|android|opera m(ob|in)i"
+"|windows (phone|ce)|blackberry"
+"|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp"
+"|laystation portable)|nokia|fennec|htc[-_]"
+"|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
string tablereg = "\\b(ipad|tablet|(nexus 7)|up.browser"
+"|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
pattern phonepat = pattern.compile(phonereg, pattern.case_insensitive);
pattern tablepat = pattern.compile(tablereg, pattern.case_insensitive);
 
public boolean checkmobile(string useragent){
if(null == useragent){
useragent = "";
}
// 匹配
matcher matcherphone = phonepat.matcher(useragent);
matcher matchertable = tablepat.matcher(useragent);
if(matcherphone.find() || matchertable.find()){
return true;
} else {
return false;
}
}
%>
<%
string path = request.getcontextpath();
string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";
 
//
string useragent = request.getheader( "user-agent" ).tolowercase();
 
if(null == useragent){
useragent = "";
}
if(checkmobile(useragent)){
response.sendredirect(basepath+"download.html");
//request.getrequestdispatcher("/download.html").forward(request,response);
} else {
response.sendredirect(basepath+"index.html");
//request.getrequestdispatcher("/index.html").forward(request,response);
}
//
%>
<!doctype html>
<html lang="zh-cn">
<head>
<base href="<%=basepath%>">
<title>测试移动设备跳转</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="测试,移动设备,跳转">
<meta http-equiv="description" content="测试移动设备跳转">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<div id="pagecontent" style="min-height:500px;_height:500px;">
正在运行!<br>
</div>
</body>
</html>

您可能感兴趣的文章:
jsp判断移动设备正则 js验证手机号码
常用js验证代码大全(Email、手机号码、身份证号码、文件类型等)
js判断字符出现次数,字符包含及手机号码验证的小例子
正则表达式判断所填入号码的运营商的js代码
多种移动手机号码正则表达式验证代码
用js正则表达式判断手机号码正确与否的代码
javascript正则验证电话号码的例子
电脑移除或更新蓝牙驱动后,已配对的蓝牙设备无法工作怎么办?
php判断是否为移动设备
js正则表达式验证电话号码

关键词: 手机验证   
[关闭]