正则表达式判断数据格式

手机号:

 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     }

 

转载于:https://www.cnblogs.com/thrive/p/3922921.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值