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.
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.
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))
`
([0-5][0-9])
. ;-) –
Nam ?
after 0
to require leading zero in hour. –
Plenish ^
at the beginning is very important because it prevents 17:30 PM
from getting mistaken as 7:30 PM
if the user inputs 24 hour time format by mistake. –
Crimple 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))
`
([0-5][0-9])
. ;-) –
Nam 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]$/
This is correct after all tests for 12-Hrs clock format,
/(((0[1-9])|(1[0-2])):([0-5][0-9]) ?([AaPp][Mm]))/
/\b(?<!:)(?=(?:[1-9]|1[012]|0\d(?=:\d))(?::[0-5]\d\b)? ?[ap]\.?m\b/i
© 2022 - 2024 — McMap. All rights reserved.