0

The title says it all.

How can I make an input accept only numbers from 4-10 and the letter M and nothing else?

Thank you

zeeks
  • 775
  • 2
  • 12
  • 30

2 Answers2

4

You can use HTML5 validation. The pattern attribute lets you specify a regular expression the value of the input must match:

<input pattern="[4-9]|10|M"
       title="Enter a number between ‘4’ and ‘10’, or the character ‘M’" 
/>
Oriol
  • 274,082
  • 63
  • 437
  • 513
1

Question already answered, follow the link, the answer there has HTML 5, JavaScript, JQuery, and more solutions. But as the answer states, don't forget to do a server side solution, because the JavaScript might be trespassed or deactivated, and the HTML5 might not work in old browsers. Don't trust user input, re-verify in server side. HTML Text Input allow only Numeric input

Community
  • 1
  • 1
Salim Mahboubi
  • 561
  • 7
  • 25