I want to create a regex that accepts a string like following:
DXXX HH:mm
where XXX
is a number from 1 to 999 but it can also accept 0 prefixed numbers like 01 and 001, but it cannot accept for example 0001 where the total length > 3
HH:mm
is the hour and minute in 24h format.
Example for accepted values: D001 14:01
and D999 00:00
I have wrote the second part which is : /^(2[0-3]|[0-1][d]):[0-5][d]$/
And for the first part: ^d{1,3}$
but this accepts 0
, 00
and 000
.
How can I solve this ?
2
Answers
Let’s keep it simple: