Username Validation in Java using Regular Expression


This example shows how to validate a Username string in Java using regular expression with Regex Pattern and Matcher validation.

Username Regular Expression Pattern:   ^[a-z0-9_-]{3,15}$

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


Share This Post On: