Archives: Validations

Java – Date Validation using Regular Expression

Date Validation in Java using Regular Expression

Date Format: dd/mm/yyyy
Regular Expression Pattern: (0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)

The above regular expression is used to validate the date format in “dd/mm/yyyy”, you can easy customize to suit your need. However, it’s a bit hard to validate the leap year, 30 or 31 days of a month, we may need basic logic as below.



Java – URL Validation using Commons UrlValidator



Java – Username Validation with Regular Expression

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

Description:
^     # 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

Example: