javascript - Input field allows only numbers and hyphens and within a specific format -
i have following code helps me insure input numbers.
however need restrict number within specific format 0000-00, using sort of alert or maybe return values false or better solution ..
<input type="text" onkeypress='validate(event)' id="class" name="class" maxlength="7" size="15px" placeholder="ex. 1504-03" required> <script> function validate(evt) { var theevent = evt || window.event; var key = theevent.keycode || theevent.which; key = string.fromcharcode( key ); var regex = /[0-9]|\./; if( !regex.test(key) ) { theevent.returnvalue = false; if(theevent.preventdefault) theevent.preventdefault(); } } </script>
your best practices appreciated
please see following link:
http://digitalbush.com/projects/masked-input-plugin/
it explains how add mask input text area. hope helps :)
admin alex
Comments
Post a Comment