How to use the pattern to delimit a minimum number in an input text?

1

Hello, I need to define that the minimum number entered in an input of type text is number 5, I tried as follows:

<input type="text" name="someName" id="someId" required="required" pattern="(([1-9]?[0-9]?[5-9]?)|([0-9]?[5-9]?)|([5-9]?))"/>

link

But it is not working, it only works if you enter 04, not just 4.

Note: minimum number 5, maximum number 999.

Thank you.

    
asked by anonymous 18.05.2016 / 05:22

1 answer

2

This will probably resolve.

 <input type="text" name="someName" id="someId" required="required" pattern="((^[5-9]$)|(^[1-9][0-9]?[0-9]$))"/>

Test HTML on jsfiddle.net

Explanation of expression:

((^[5-9]$)|(^[1-9][0-9]?[0-9]$))
  • ^ start of list
  • [5-9] takes any value from 5 to 9
  • $ end of list
  • | "or". So lets search the next regex if the first fails
  • ^[1-9][0-9] this takes any value from 10 to 99 (*)
  • [0-9]$ = optional ai takes anything from 1 to 9 that is the last character in the list.

(*) - ? means optional. When put like this within ^[1-9][0-9]?[0-9]$ it means that the verification of the medium is optional, which allows numbers between 10 and 99.

    
18.05.2016 / 07:21