lili
lili

Reputation: 17

how to limit my input with only some numbers using pattern?

Hello i have the following input :

<input type="text" name="morningS" class="morningS" id="morningS" pattern="[0-23]+,[00|25|50|75]$"/>

im trying to limit it to something like this : "the numbers before the ',' should be between 0 and 23 only and the number after can only be "00" "25" "75" or "50" but the pattern i added isnt working , anyone can help please ?

Upvotes: 0

Views: 62

Answers (1)

b4tch
b4tch

Reputation: 1188

This seems to do the trick...

<input type="text" name="morningS" class="morningS" id="morningS" required pattern="^[0-23]+,(00|25|50|75)$" title="Format should be 0-23 followed by a comma, then one of 00, 25, 50, or 75"/>

Essentially I just changed the square brackets to regular ones. I also added a title attribute to enable browsers that support it to describe the required pattern to users.

Upvotes: 1

Related Questions