String解析 String regex="(13[4-9]|15[01789]|18[78])\\d{8}";if(str.matches(regex)){ System.out.println(str+"是一个移动号");} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果不用正则可以自己判断一下。使用indexOf函数 public static void main(String[] args){ String str = "134,135,136,137,138,139,150,151,157,158,159,187,188"; String s = "1235903"; if(str.indexOf(s.substring(0,3))>=0){//是移动号码 System.out.println("AAAAAAAAAAAA"); }else{ System.out.println("BBB"); } } public class Regular { public static void main(String[] args) { String match = "^1((3[4-9])|(5[0|1|7-9])|(8[7|8]))\\d*"; for (String s : tests) { if ( s.matches(match)) { System.out.println(s + " matches"); } else { System.out.println(s + " does not match"); } } } private static String[] tests = { "13112345678", "13212345678", "13312345678", "13412345678", "13512345678", "13612345678", "13712345678", "13812345678", "13912345678", "15012345678", "15112345678", "15212345678", "15312345678", "15412345678", "15512345678", "15612345678", "15712345678", "15812345678", "15912345678", "18112345678", "18212345678", "18312345678", "18412345678", "18512345678", "18612345678", "18712345678", "18812345678", "18912345678" };} 解决方法太多了。至少if else就是一个好方法。至于怎么存放,数据库,普通文件,配置文件都可以。你至少要先试一下吧? struts2 报错 找不到方法? xpath有读取xml文本内容 或者 属性值的功能吗 不带XML文档标签 纯文本 无法解析指定的连接标识符 谁有基于struts2 可以改pop3的邮件收发的源码啊 有关在Struts1.x中配置数据源时出现的问题,急!! SAXReader解析xml问题 急:struts2中页面导向问题 rmi抛出java.security.AccessControlException异常,是什么原因 我需要com和ejb之间通讯 什么样的项目会用到Junit ? hibernate 自定义类型问题 Spring配置文件使用命名空间的问题
使用indexOf函数 public static void main(String[] args){
String str = "134,135,136,137,138,139,150,151,157,158,159,187,188";
String s = "1235903";
if(str.indexOf(s.substring(0,3))>=0){//是移动号码
System.out.println("AAAAAAAAAAAA");
}else{
System.out.println("BBB");
}
}
public static void main(String[] args) { String match = "^1((3[4-9])|(5[0|1|7-9])|(8[7|8]))\\d*"; for (String s : tests) {
if ( s.matches(match)) {
System.out.println(s + " matches");
} else {
System.out.println(s + " does not match");
}
}
} private static String[] tests = {
"13112345678",
"13212345678",
"13312345678",
"13412345678",
"13512345678",
"13612345678",
"13712345678",
"13812345678",
"13912345678",
"15012345678",
"15112345678",
"15212345678",
"15312345678",
"15412345678",
"15512345678",
"15612345678",
"15712345678",
"15812345678",
"15912345678",
"18112345678",
"18212345678",
"18312345678",
"18412345678",
"18512345678",
"18612345678",
"18712345678",
"18812345678",
"18912345678"
};
}