Skip to content

Instantly share code, notes, and snippets.

@sirius2k
Last active June 16, 2018 07:41
Show Gist options
  • Save sirius2k/df44c9d6adde627e89366c641c451779 to your computer and use it in GitHub Desktop.
Save sirius2k/df44c9d6adde627e89366c641c451779 to your computer and use it in GitHub Desktop.
ID, Password regexp pattern
// Id starts with alphabet and alphanumeric characters. Minimum length 4, Maximum length 20.
@Pattern(regexp = "^[a-zA-Z]{1}[a-zA-Z0-9_]{4,20}$")
// Password requires at least number, capital character, non-capital character and special character. Minimum length 8, Maximum length 20.
// ^ # start-of-string
// (?=.*[0-9]) # a digit must occur at least once
// (?=.*[a-z]) # a lower case letter must occur at least once
// (?=.*[A-Z]) # an upper case letter must occur at least once
// (?=.*[@#$%^&+=]) # a special character must occur at least once
// (?=\S+$) # no whitespace allowed in the entire string
// .{8,20} # anything, at least eight places at most 20 though
//$ # end-of-string
@Pattern(regexp = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment