日期:2014-05-18  浏览次数:20636 次

求中国电话的正则表达式
求中国电话的正则表达式

------解决方案--------------------
String regexp = "(\\+?[0-9]{1,4})?[ ]*([0-9]{1,}\\-?){1,2}[0-9]+$ ";
------解决方案--------------------
String regex = "(0\\d{2,3}-)?\\d{7,8} ";
System.out.println( "025-12345678 ".matches(regex));
------解决方案--------------------
其实这个问题我还是不懂,但是,我更想问的是,比如,关于若干行业的业务逻辑,是否可以归结出一定量的正则表达式的呢,比如电信行业,教育行业,工资计费,消费积分,超市物流系统之类的。不知道是否有专家能给写出成一定的文件包(PDF,DOC,CHM甚至html都可以),便于下载之类的呢。
期待中
------解决方案--------------------
移动手机的怎么判断?

还有如何把全角数字自动转换成半角的??
------解决方案--------------------
public static void main(String[] args) {
  String num = "0123456789 ";
  System.out.println(replaceNumber(num));
  
  String phone = "13045678944 ";    
  System.out.println(chinaUnicom(phone));
  
  phone = "13845678944 ";
  System.out.println(chinaMobile(phone));
}

// 替换全身数字
public static String replaceNumber(String num) {    
  for(char c = '0 '; c <= '9 '; c++){
    num = num.replace(c+ " ", (c - '0 ') + " ");
  }
  return num;
}

// 移动号段 134~139、158~159
public static boolean chinaMobile(String pn){
  return pn.matches( "((13[4-9])|(15[8-9]))\\d{8} ");
}

// 联通号段 130~133、156
public static boolean chinaUnicom(String pn){
  return pn.matches( "((13[0-3])|(15[6]))\\d{8} ");
}
------解决方案--------------------
\d{3}-\d{8}|\d{4}-\d{7}
------解决方案--------------------
\d[3]-\d[8]|\d[4]-\d[7]|\d[4]-\d[8]
北京010-33333333
荆州0716-8438243
杭州0571-87653465