sushma_proach

form validation with caracters....

Apr 16th, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <form action="" method="post" onsubmit="s()">
  2.   First name:<br>
  3.   <input type="text" name="firstname" id="name">
  4.   <br>
  5.   Last name:<br>
  6.   <input type="text" name="lastname" id ="last">
  7.   <input type="submit" name="sub" value="submit" />
  8. </form>
  9.  
  10. <script>
  11. function s()
  12. {
  13. var alphaExp = /^[0-9a-zA-Z]+$/;
  14. var t=document.getElementById("name").value;
  15. if(t.match(alphaExp))
  16. {
  17. alert("your field is valid");
  18. return true;
  19. }
  20. else
  21. {
  22. alert("your field is wrong");
  23. return false;
  24. }
  25. }
  26. </script>
Add Comment
Please, Sign In to add comment