Password Regular Expression Pattern
for more regular expression syntax refer Java Regular Expression Syntax Descriptions
PasswordValidator.java
Output :
((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#^$%!&]).{8,14})Regular ExpressionDescription
for more regular expression syntax refer Java Regular Expression Syntax Descriptions
PasswordValidator.java
package com.javatutorialcorner.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PasswordValidator { private static final String PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#^$%!&]).{8,14})"; public static void main(String[] args) { System.out.println("Validate Valid pattern - Abc12@abc : "+validate("Abc12@abc")); System.out.println("Validate No Uppercase - JTC123 : "+validate("abc12@abc!")); System.out.println("Validate No Upper case No Speacial character - abc1234 : "+validate("abc1234")); System.out.println("Validate Less than 8 character - aBc@1! : "+validate("aBc@1!")); System.out.println("Validate More than 14 characer @JavaTutorialCornor : "+validate("@JavaTutorialCornor")); } private static boolean validate(String password) { Pattern pattern = Pattern.compile(PATTERN); Matcher matcher = pattern.matcher(password); return matcher.matches(); } }
Output :
Validate Valid pattern - Abc12@abc : true
Validate No Uppercase - JTC123 : false
Validate No Upper case No Speacial character - abc1234 : false
Validate Less than 8 character - aBc@1! : false
Validate More than 14 characer @JavaTutorialCornor : false
0 comments:
Post a Comment