1 手机号正则表达式
(1) 手机号开头集合
176,177,178,
180,181,182,183,184,185,186,187,188。,189。
145,147
130,131,132,133,134,135,136,137, 138,139
150,151, 152,153,155,156,157,158,159,
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
(2) 正则表达式
/**
* 验证手机号码是否合法
*/
public static boolean validatePhoneNumber(String mobiles) {
String telRegex = "^((13[0-9])|(15[^4])|(18[0-9])|(17[0-8])|(147,145))\\d{8}$";
return !TextUtils.isEmpty(mobiles) && mobiles.matches(telRegex);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
2 身份证号码正则表达式
/**
* 验证身份证号码是否合法
*/
public static boolean validateIDCardNumber(String number) {
return (number.length() == 15 && number.matches("^\\d{15}"))
|| (number.length() == 18 && (number.matches("^\\d{17}[x,X,\\d]")));
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
3 正则表达式匹配URL
(1) 判断是否是完整的域名
public static boolean isCompleteUrl(String text) {
Pattern p = Pattern.compile("((http|ftp|https)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?", Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(text);
return matcher.find();
}
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
(2)判断是否是缺少前缀的域名
/**
* 是否是缺少前缀的域名
*/
public static boolean isHalfCompleteUrl(String text) {
Pattern p = Pattern.compile("(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?", Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(text);
return matcher.find();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
4 其他的正则表达式
/**
* 验证工具类
*/
public class ValidateUtil {
private static final int PASS_LOW_LIMIT = 6;
private static final int PASS_HIGH_LIMIT = 16;
/**
* 验证手机号码是否合法
*/
public static boolean validatePhoneNumber(String mobiles) {
String telRegex = "^((13[0-9])|(15[^4])|(18[0-9])|(17[0-8])|(147,145))\\d{8}$";
return !TextUtils.isEmpty(mobiles) && mobiles.matches(telRegex);
}
/**
* 验证密码是否合法 6-16位
*/
public static boolean validatePass(String password) {
return password.length() >= PASS_LOW_LIMIT && password.length() <= PASS_HIGH_LIMIT;
}
/**
* 验证身份证号码是否合法
*/
public static boolean validateIDCardNumber(String number) {
return (number.length() == 15 && number.matches("^\\d{15}"))
|| (number.length() == 18 && (number.matches("^\\d{17}[x,X,\\d]")));
}
/**
* 判断是不是英文字母
*/
public static boolean isECharacter(String codePoint) {
return codePoint.matches("^[A-Za-z]$");
}
}
原文链接:http://blog.csdn.net/chenliguan/article/details/73486474