I'm trying to make a date textbox on my blog, and the date is only numbers. I don't want anybody making a mistake typing a letter. Is there any way to limit the characters to only numerals? Thanks!
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
you need some java script to implement this
If you use jQuery, you can do it like in this jsfiddle
Yes, you need some JavaScript to do this. I found the JQuery date picker widget very useful to do exactly what you're wanting. The code that used to implement it is:
html to create the text field and not allow manual manipulation:
the JS line binding the picker to the field with a specific format that my server side process is expecting:
You can find more information here: http://jqueryui.com/datepicker/
Use HTML5 input number type instead and leverage native browser validation. Thus, no JavaScript required.
It has wide support in browsers and it's the standard and best-practice solution.
Also on
mobile
andtablets
the numeric key pad will appear instead.See demo
Try this (utilizing jquery javascript library)
html
js (jquery library)
jsfiddle http://jsfiddle.net/guest271314/v2BRY/
Edit. Not certain if
element
isinput
ottextarea
, hope should work for either.javascript, without utilizing jquery javascript library
html
javascript
jsfiddle http://jsfiddle.net/guest271314/pFu4K/
Hope this helps