/ Published in: JavaScript
restrict max length of a text box containing first position with a digit followed by a space
Expand |
Embed | Plain Text
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript"> function youcancall_dumbs() { var d = document.getElementById('dumb').value; if(!isNaN(d.charAt(0)) && d.charAt(0)!='') { document.getElementById('dumb').value= d.charAt(0)+' '; } else { alert('Please enter only digits at first place'); document.f1.dumb.value=""; document.getElementById('dumb').focus(); } } </script> </head> <body> <form name="f1"> <input type="text" name="dumb" id="dumb" maxlength="2" onkeyup="youcancall_dumbs()" /> </form> </body> </html>
You need to login to post a comment.
