Nov 8, 2018

Java Regular Expression Examples

Username Regular Expression Pattern

^[a-z0-9_-]{3,16}$


^
Start
[a-z0-9_-]
Match characters and symbols in the list, a-z, 0-9 , underscore , hyphen
{3,16}
Length at least 3 characters and maximum length of 16
$
End

Password Regular Expression Pattern

((?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@#&$%]).{8,88})


(
Start of group
(?=.*[A-Z])
must contains one uppercase characters
(?=.*[a-z])
must contains one lowercase characters
(?=.*\d)
must contains one digit from 0-9
(?=.*[@#&$%])
must contains one special symbols in the list "@#&$%"
.
match anything with previous condition checking
{8,88}
length at least 8 characters and maximum of 88
)
End of group