Kevin
Kevin

Reputation: 35

HTML5 pattern attribute not working

I have a form on my webpage that needs to make sure that the text a user is entering is in the proper format; however, it doesn't seem to be preventing the form submission when data of an incorrect format is entered. For example, the input needs to be a time of the format HH:MM am/pm and when I submit the form with a value of "a" in the field, it accepts the value when it shouldn't be.

Below is the code for the input:

<input id='timepicker' class="required" type='text' data-ng-model = "time" name='timepicker' pattern="(1[0-2]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)" title="Time in HH:MM am/pm format" required>

Any help would be greatly appreciated

Upvotes: 0

Views: 151

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

\s must not be escaped (it's not java), (?i) is not supported:

pattern="(1[0-2]|0?[1-9]):[0-5][0-9]\s?[aApP][mM]"

Upvotes: 1

Related Questions