常用验证功能正则表达式及使用正则表达式进行验证

1 Java中使用正则表达式

String rexExpStr = "正则表达式串";//正则表达式

Strng targetStr = "待验证字符串";//要想进行验证的字符串内容

Pattern p_postcode = Pattern.compile(rexExpStr);
Matcher m_postcode = p_postcode.matcher(targetStr);
if (m_postcode.find()) {//满足验证条件
     //Business codes

    ........
}else{//不满足验证条件

    .......

}

2 常用的正则表达式

public final static String REG_int = "^\\d*$";
 public final static String REG_float = "^\\d+(\\.\\d+)?$";
 public final static String REG_date = "^[\\d]{4}([-][\\d]{2}){2}$";
 public final static String REG_time = "^[\\d]{4}([-][\\d]{2}){2}([ ][12]{1}[\\d]{1}([:][123456]{1}[\\d]{1}){2}){1}$";
 public final static String REG_datetime = "^[\\d]{4}([-][\\d]{2}){2}([ ][12]{1}[\\d]{1}([:][123456]{1}[\\d]{1}){2}){1}$";
 public final static String REG_email = "^[\\w\\d]+@[\\w\\d]+(\\.[\\w\\d]+)+$";
 public final static String REG_phone = "^(\\d+[-]){0,2}\\d+$";
 public final static String REG_mobile = "^[1]\\d{10}$";
 public final static String REG_postcode = "^\\d{6}$";
 public final static String REG_url = "^[\\w]+[:][/]{2}([\\w]+\\.)+([\\w]+[/])+[\\w\\.]*$";
 public final static String REG_year = "^\\d{4}$";
 public final static String REG_month = "^\\d{1,2}$";
 public final static String REG_day = "^\\d{1,2}$";

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值