android正则匹配账号密码信息

/**

正则表达式,java与android稍有不同,如java中\s+ 需要加多\ 变成 \\s+,

android匹配字符

*+ Zero or more (possessive).
?+ Zero or one (possessive).
++ One or more (possessive).
{n}+ Exactly n (possessive).
{n,}+ At least n (possessive).
{n,m}+ At least n but not more than m (possessive).

**/

/**

* 是否为账号规范
* 如:
* 6~18个字符,可使用字母、数字、下划线,需以字母开头

* @param text
* @return
* @author luman
*/
public static boolean isAccountStandard(String text) { 
//不能包含中文
if(hasChinese(text)){
return false;
}

/**
* 正则匹配:
* [a-zA-Z]:字母开头
* \\w :可包含大小写字母,数字,下划线,@
* {5,17} 5到17位,加上开头字母  字符串长度6到18
*/
String format = "[a-zA-Z](@?+\\w){5,17}+";
if(text.matches(format)){
return true;
}
return false;
}


/**
* 是否为密码规范

* @param text
* @return
* @author luman
*/
public static boolean isPasswordStandard(String text) { 


//不能包含中文
if(hasChinese(text)){
return false;
}


/**
* 正则匹配
* \\w{6,18}匹配所有字母、数字、下划线 字符串长度6到18(不含空格)
*/
String format = "\\w{6,18}+";
if(text.matches(format)){
return true;
}
return false;
}



/**
* 中文识别
*
*@author luman
*/
public static boolean hasChinese(String source)  { 
      String reg_charset = "([\\u4E00-\\u9FA5]*+)"; 
      Pattern p = Pattern.compile(reg_charset); 
      Matcher m = p.matcher(source); 
      boolean hasChinese=false;
      while (m.find()) 
      { 
      if(!"".equals(m.group(1))){
      hasChinese=true;
      }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值