Android 点滴记录

一:判断我们输入的密码,(长度,大小写字母,特殊字符)

        

 private static Pattern pattern1 = Pattern.compile("[a-z]+");
    private static Pattern pattern2 = Pattern.compile("[A-Z]+");
    private static Pattern pattern3 = Pattern.compile("[0-9]+");
    private static Pattern pattern4 = Pattern.compile("\\p{Punct}+");
    private static Pattern pattern5 = Pattern.compile("[a-zA-Z]+.*");

   Matcher matcher1 = pattern1.matcher(password);
        Matcher matcher2 = pattern2.matcher(password);
        Matcher matcher3 = pattern3.matcher(password);
        Matcher matcher4 = pattern4.matcher(password);
        if(password.length()<8||password.length()>20){
            Toast.makeText(context,"密码长度需设置为8到20位",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(matcher1.find()){
//            Log.e(TAG,"找到小写字母");
        }else {
            Toast.makeText(context,"密码需要包含小写字母",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(matcher2.find()){
//            Log.e(TAG,"找到大写字母");
        }else {
            Toast.makeText(context,"密码需要包含大写字母",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(matcher3.find()){
//            Log.e(TAG,"找到数字");
        }else {
            Toast.makeText(context,"密码需要包含数字",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(matcher4.find()){
//            Log.e(TAG,"找到特殊字符");
        }else {
            Toast.makeText(context,"密码需要包含特殊字符",Toast.LENGTH_SHORT).show();
            return false;
        }



 Matcher matcher1 = pattern5.matcher(username);
        if(matcher1.matches()){
//            Log.e(TAG,"找到特殊字符");
        }else {
            Toast.makeText(context,"用户名需要字母开头",Toast.LENGTH_SHORT).show();
            return false;
        }

         

猜你喜欢

转载自blog.csdn.net/Liuxb_zao/article/details/82787145