I modified the original to this:
^(?:(?:(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec))(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:(?:0?2|(?:Feb))(\/|-|\.)(?:29)\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
I would do the initial validation with
^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$
I have added ^
to indicate the start of the string and I have removed |
(it is union operator, OR) from the end of your original regex. I tested it here .
You have space after the $ sign, that's why you input doesn't match.
[0-9]{2}\/[0-9]{2}\/[0-9]{4}$ |
// here __^
Remove it ( [0-9]{2}\/[0-9]{2}\/[0-9]{4}$
) and, if you want to accept empty string, add empty string with a group, and add beginning of string anchor:
^([0-9]{2}\/[0-9]{2}\/[0-9]{4}|)$
or, better, make the group optional
^([0-9]{2}\/[0-9]{2}\/[0-9]{4})?$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.