Hi friends I was wondering if there is an html input type that only accepts float or integer values and does not accept other characters such as letters and so on. I tried input type as number but it also accepts other characters. If possible could you help me with this please?
Asked
Active
Viewed 2,707 times
0
-
1Which browser accepts letters for ``? Sounds very wrong if what you're saying is true. – light Jul 14 '15 at 09:11
-
1See [this question](http://stackoverflow.com/questions/19011861/is-there-a-float-input-type-in-html5?rq=1) and [this question](http://stackoverflow.com/questions/8808590/html5-number-input-type-that-takes-only-integers?rq=1). – Glorfindel Jul 14 '15 at 09:11
-
Are you trying to prevent users from even typing letters? Or do you just want the form to reject the values with error? What is your current code? – light Jul 14 '15 at 09:12
-
Please don't post a question that you haven't tried to solve. You should attempt to solve it yourself first. If you have tried, you can then include your code and research in your question to show what hasn't worked for you. It makes your question easier for others to answer too! – SuperBiasedMan Jul 14 '15 at 09:17
-
Well I just wrote I thought it will accept only numbers but it also accepts letters.Both for Chrome and Firefox it accepts letters. – Shahin Jul 14 '15 at 09:57
1 Answers
1
There is no such type but you can use HTML5 pattern attribute and validate it using Regex. Example :
<form action="#">
<input type="text" pattern="[\d]+" title="Numbers">
<input type="Submit" value="Validate">
</form>
If you want to learn more about regex and pattern attribute check this link : http://www.w3schools.com/tags/att_input_pattern.asp

Shehroz Ahmed
- 537
- 4
- 16