Java library for username validation for general use and with bean validation api. It has all constraints for google like username validation and many more.
Library has different constraint to deal with username validation:
- UsernamePattern to allow a-z,0-9,period and underscore characters. These characters can we turned off with some flags in constraints like includePeriod, includeUnderscore and useDigit
- EndWithAlphabet to check if username end with alphabet
- StartWithAlphabet to check if username start with alphabet
- StartWithAlphaNumeric to check username start with alphanumeric
- EndWithAlphaNumeric to check username end with alphanumeric
- NotContainConsecutivePeriod to check username not contain consecutive period
- NotContainConsecutiveUnderscore to check username not contain consecutive underscore
- NotContainPeriodFollowedByUnderscore to check username not contain period followed by underscore
- NotContainUnderscoreFollowedByPeriod to check username not contain underscore followed by period
All the constraints by default ignore blank so that it will be reported separately by NotBlank standard bean validation constraint and same can we turned of using ignoreBlank(true by default) flag of each constraint.
So simple example like to use library can be like this:
@UsernamePattern
@StartWithAlphaNumeric
@NotContainConsecutivePeriod
@EndWithAlphaNumeric
@NotBlank
private String username;
Use the library by simply including the maven coordinates in your project:
<dependency>
<groupId>com.github.ankurpathak.username</groupId>
<artifactId>username-validation</artifactId>
<version>1.3</version>
</dependency>
For help regarding other build tools visit the Maven Homepage of project.