1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('#text').keypress(function (e) { var regex = new RegExp("^[a-zA-Z0-9]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); }); </script> <form action="submitpage.php" method="post" name="form1"> Name: <input type="text" name="box1" id="text"><br> Age: <input type="text" name="box2"><br> <input type="submit" name="submit" value="Add info"> </form> |