I have a textbox and i want the input for the textbox to satisfy to conditions: a) It should be a number b) It be should be greater than 5. What should be the regular expression for that?
Asked
Active
Viewed 315 times
-1
-
try this. [6-9][0-9]* – Dinesh Suthar Sep 21 '17 at 06:15
-
you can check the number is valid or not like here : `(([1-5]\d|[6-9]))$` [see the test results here](https://regex101.com/r/vX3dU0/7) – Rahul Hendawe Sep 21 '17 at 06:19
-
1@DineshSuthar How would this allow for a number such as 28? – kojow7 Sep 21 '17 at 06:27
-
@RahulHendawe How would this allow for a number such as 8214? Also, why the double parentheses? – kojow7 Sep 21 '17 at 06:27
-
Can you more spefic? – soorapadman Sep 21 '17 at 06:28
1 Answers
2
Instead of regex
you can use <input type='number'
... Check snippet below
<input type="number" name="quantity" min="6" />

Super User
- 9,448
- 3
- 31
- 47
-
-
@DucFilan Ya its not working if we directly enter the number. – Aarthna Maheshwari Sep 21 '17 at 06:40
-
@AarthnaMaheshwari it automatically validate the value on `submit or blur` event. You can check. – Super User Sep 21 '17 at 06:42
-
@DucFilan This kind of specification will be supported by the most browsers, including the old ones. – SacrumDeus Sep 21 '17 at 06:47
-
-
@DucFilan it Support all major browsers which you can check in following link `http://caniuse.com/#search=number`. – Super User Sep 21 '17 at 06:56
-
-
If you would like to watch the global stats of browser usage, you will see, that the IE<10 will be used by a very small percentage of all Browser users. This is a unimportant share. Here is the statistics: [W3Counter](https://www.w3counter.com/globalstats.php) – SacrumDeus Sep 21 '17 at 09:54