Pattern Validation

//Validation email.    

private boolean checkEmail(String email) {

        String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(email);
        if (!matcher.matches())
            return false;
        else
            return true;

    }

//Validation password

        String passwordPattern ="[\\sA-Za-z0-9&().-]+";
        Pattern pattern = Pattern.compile(passwordPattern);

//Validation postcode

        Pattern pattern = Pattern.compile("\\d{1,6}");
        Matcher matcher = pattern.matcher(postal);

//Validaton mobile

        Pattern pattern = Pattern.compile("[0-9]{1,12}");
        Matcher matcher = pattern.matcher(mobileNo);




Java代码   收藏代码
  1. package test;  
  2.   
  3. import java.util.regex.Matcher;  
  4. import java.util.regex.Pattern;  
  5.   
  6. public class TestPassword {  
  7.     public static void main(String args[]){  
  8.         String password="hahymfghdfg";  
  9.           
  10.         Pattern   p   =   Pattern.compile("[A-Z]+");     
  11.         Pattern   q   =   Pattern.compile("[a-z]+");     
  12.         Pattern   r   =   Pattern.compile("[0-9]+");     
  13.         Pattern   s   =   Pattern.compile("\\p{Punct}+");     
  14.           Matcher   m1   =   p.matcher(password);     //判断是否含有大写字符     
  15.         Matcher   m2=   q.matcher(password);   //判断是否含有小写字符     
  16.         Matcher   m3   =   r.matcher(password);//判断是否含有数字     
  17.         Matcher   m4   =   s.matcher(password);//判断是否含有特殊字符     
  18.           if(m2.find(0)&&( !m4.find(0)) ){  
  19.               System.out.println("密码符合规则");   
  20.           }  
  21.           else{                                                           
  22.                System.out.println("密码不符合规则");    
  23.           }  
  24.           
  25.     }  
  26.   
  27. }   



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值