字符串的合法验证
2017-09-19 17:22
204 查看
//1开头,第二位从3,5,8取值,后面的9位[0,9]取值 public static boolean isPhoneByPattern(String phone) { String regex = "^1[3|5|8]\\d{9}$"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(phone); return matcher.matches(); } public static boolean isPhoneByString(String phone) { // "[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。 String regex = "[1][358]\\d{9}"; return phone.matches(regex); } public static boolean isEmailByPattern(String email) { String regex = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(email); return matcher.matches(); } public static boolean isEmailByString(String email) { String regex = "([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)"; return email.matches(regex); } public static boolean isICNOByPattern(String icno) { String regex15 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$"; Pattern pattern15 = Pattern.compile(regex15); Matcher matcher15 = pattern15.matcher(icno); String regex18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|x|X)$"; Pattern pattern18 = Pattern.compile(regex18); Matcher matcher18 = pattern18.matcher(icno); return (matcher15.matches() || matcher18.matches()); } public static boolean isICNOByString(String icno) { String regex15 = "[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}"; String regex18 = "[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|x|X)"; return (icno.matches(regex15) || icno.matches(regex18)); }
相关文章推荐
- 验证字符串是否是合法的日期格式
- 使用inet_pton验证字符串是否是合法的ipv4或ipv6地址
- 字符串处理_验证文件名和邮箱地址是否合法
- 一段可以验证给定的IP地址字符串是否合法的bash脚本
- C#验证给定字符串形式日期是否合法的方法
- C# 验证给定的字符串形式的日期是否合法
- java字符串操作,验证输入的身份证合法与否
- js用','切割字符串之后验证
- 字符串转换为合法IP地址
- JAVA 判断一个字符串是不是一个合法的日期格式
- 验证密码字符串(正则表达式)
- 转贴 有关js 函数验证和字符串查找替换的方法
- 判断某个字符串是不是一个合法的IP地址
- 验证身证是否合法,并且取得里面的生日日期
- Java正则表达式 做校验验证字符串中全是字符和数字组成
- java 嵌入js线程异步调用和验证字符串是否json格式
- 关于登陆验证中字符串的比较的小阴沟
- [收藏]几个常用的用正则表达式验证字符串的函数
- 验证字符串长度范围
- 去除字符串前后的逗号;验证特殊字符