Reputation: 13
I constructed a regex to match datetimes in the format dd.mm.yyyy hh:ii. This works great on regex tester: https://regex101.com/r/AX4nxj/1 But when used in the pattern attribute of an input field it does not validate at all. You can even type just "a" and it will submit.
<input type="text" required="required" pattern="(?:(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))\.(?:0[1-9]|1[0-2])\.(?:19|20)[0-9]{2}\ (?:[01]\d|2[0-3]):[0-5]\d" name="formName" />
You can try it yourself: http://jsfiddle.net/h2uwhL70/
Why is that? :( Does HTML use a different regex format or what?
Upvotes: 0
Views: 736
Reputation: 1054
I think your regex is a little bit verborage and wrong :D. So try this:
^(0+[1-9]|[1-2]+[0-9]|3+[0-1]).(0+[1-9]|1+[0-2]).\d{4} (00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9])$
Upvotes: 1