How To Validate 12-hour Time With Regex (regular Expression)
I want to validate a 12-Hours time format like (01:05 PM) in PHP, Javascript and HTML. I tried this: ((([1-9])|(1[0-2])):([0-5])(0|5)\s(A|P)M) But I don't know why it doesn't work
Solution 1:
Solution 2:
try this :
(((0[1-9])|(1[0-2])):([0-5])([0-9])\s(A|P)M)
test regex here
try this for case sensitive AM|PM|am|pm : `
(((0[1-9])|(1[0-2])):([0-5])(0|5)\s(A|P|a|p)(M|m))
`
Solution 3:
This will work for both pm/am and PM/AM and prefixed with or without 0(Zero)
/^(0?[1-9]|1[012])(:[0-5]\d) [APap][mM]$/
Post a Comment for "How To Validate 12-hour Time With Regex (regular Expression)"