Regular Expression In Android for Password Field

前端 未结 10 1146
执念已碎
执念已碎 2020-12-13 09:56

How can i validating the EditText with Regex by allowing particular characters . My condition is :

Password Rule:

  1. On

10条回答
  •  误落风尘
    2020-12-13 10:26

    try {
        if (subjectString.matches("^(?=.*[@$%&#_()=+?»«<>£§€{}\\[\\]-])(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).*(?<=.{4,})$")) {
            // String matched entirely
        } else {
            // Match attempt failed
        } 
    } catch (PatternSyntaxException ex) {
        // Syntax error in the regular expression
    }
    
    
    (?=.*[@\$%&#_()=+?»«<>£§€{}.[\]-]) -> must have at least 1 special character
    (?=.*[A-Z])   -> Must have at least 1 upper case letter
    (?=.*[a-z])   -> Must have at least 1 lower case letter
    (?=.*\\d)     -> Must have at least 1 digit
    (?<=.{4,})$") -> Must be equal or superior to 4 chars.
    

提交回复
热议问题