accept only number in input text box without using script

*爱你&永不变心* 提交于 2019-12-11 09:29:31

问题


How to allow only number in input text box

<input type="text" name="price" id="input-country" required placeholder="Enter Your Price" accept="number">

i used the above method but its not working when i use only allowed type in image input i use the following method

<input type="file" class="custom-file-input" accept="image/x-png, image/gif, image/jpeg">

this method works fine in same way how to allow only number and how to allow only text, and protect form SQL injection


回答1:


Click this for checking how to enter numeric text only in HTML

If you are using HTML5 then use <input type="number">

If you realy wish to get rid of SQL injection Use this




回答2:


You can use javascript like:

<input type="text" onkeypress="return event.charCode >= 48 && event.charCode <= 57">

The above code only accepts numbers.

If you want to use decimal number then you can use like:

<input type="text" onkeypress="return event.charCode >= 46 && event.charCode <= 57">

Try this code, maybe it will help.



来源:https://stackoverflow.com/questions/25589758/accept-only-number-in-input-text-box-without-using-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!