手机号:
1 public boolean customerPhonenumber(String customerPhonenumber){ 2 boolean IsRight=false; 3 // \\+\\d{13}|\\d{11} 4 String regex1="[1][\\d]{10}"; 5 String regex2="[+][\\d]{13}"; 6 if(customerPhonenumber.matches(regex1)) { 7 IsRight=true; 8 }else if(customerPhonenumber.matches(regex2)){ 9 IsRight=true; 10 }else{ 11 IsRight=false; 12 } 13 return IsRight; 14 }
6-10位标示符(除$ ,即 字母,数字,下划线)
1 public boolean customerUsernameOrPasswordFormat(String customerUsernameOrPassword ){ 2 boolean IsRight=false; 3 String regex="\\w{6,10}"; 4 if(customerUsernameOrPassword.matches(regex)) { 5 IsRight=true; 6 } 7 8 return IsRight; 9 } 10
6位数字
1 public boolean accountIdFormat(String customerId ){ 2 boolean IsRight=false; 3 String regex="\\d{6}"; 4 if(customerId.matches(regex)) { 5 IsRight=true; 6 } 7 8 return IsRight; 9 }
二选一
1 public boolean AccountType(String accountType) { 2 boolean IsRight=false; 3 if(accountType.equalsIgnoreCase("saving")|| accountType.equalsIgnoreCase("current")){ 4 IsRight=true; 5 }else { 6 IsRight=false; 7 } 8 return IsRight; 9 10 }
正则表达式判断数据格式
时间: 2024-10-15 19:21:00