码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式判断数据格式

时间:2014-08-19 20:42:05      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   数据   for   div   log   on   

手机号:

 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     }

 

正则表达式判断数据格式,布布扣,bubuko.com

正则表达式判断数据格式

标签:style   blog   color   数据   for   div   log   on   

原文地址:http://www.cnblogs.com/thrive/p/3922921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!