Posted By

brianyang on 09/04/09


Tagged

form element require digit


Versions (?)

require at least one digit


 / Published in: JavaScript
 

  1. <script language="JavaScript1.2">
  2. function requireDigit(){
  3. var needDigit = /\d/
  4. if (document.myform.myinput.value.search(needDigit) == -1)
  5. alert("at least one number req'd")
  6. else {
  7. alert('alright we see your digit(s)')
  8. }
  9. }
  10. </script>
  11. <form name="myform">
  12. <input type="text" name="myinput" size=15><input type="button" onClick="requireDigit()" value="check">
  13. </form>

Report this snippet  

You need to login to post a comment.