Hi,
I am using jdk regular expression to validate the password.
These are the requirements for valid password:
- password length
minimum 4 characters
maximum 8 characters
- at least one character
- at least one number
- can contain any of the following characters
! @ # $ % ^ &
I could able to validate most of my requirements, expect the last one (related to special characters). Can anyone help me:
Am attaching my code here:
- Kishore
public class ValidatePassword {
public static void main(String args[]) {
if(args.length < 1) {
System.out.println("Usage: ValidatePassword <password>");
}
String password = args[0];
System.out.println( password + " is : "
+ (password.matches("^([\\p{Alnum}]*)$")
&& password.length() >= 4
&& password.length() <= 6));
//I would like to know how to use the range option {4,6} is not working in able example
//and also would like to know how to validate only !@#$%^ characters along with alphanumerics
}
}