java regex pattern validate password

Regular expression password pattern


This regular expression refers to a pattern with at least one digit, one upper case letter, one lower case letter and one special symbol (“@#$%”).


package com.w3spoint;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
	private static final String PATTERN = 
	public static void main(String args[]){ 
		List<String> values = new ArrayList<String>();	
		values.add("[email protected]"); 
		values.add("[email protected]");
		Pattern pattern = Pattern.compile(PATTERN);
		for (String value : values){
		  Matcher matcher = pattern.matcher(value);
			  System.out.println("Password "+ value +" is valid");
			  System.out.println("Password "+ value +" is invalid");


Password [email protected] is valid
Password Sjai12$ is valid
Password [email protected] is invalid
Password jai* is invalid
Content Protection by
Please Share