Hendripanjaitan

HTML + JS validasi noHP.

Sep 10th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title></title>
  5.   <script type="text/javascript">
  6.   function validasi_input(form){
  7.   if (form.telp.value != ""){
  8.   var x = (form.telp.value);
  9.   var status = true;
  10.   var list = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
  11.   for (i=0; i<=x.length-1; i++)
  12.  {
  13.  if (x[i] in list) cek = true;
  14.  else cek = false;
  15. status = status && cek;
  16.  }
  17.  if (status == false)
  18.  {
  19.  alert("Telp harus angka!");
  20.  form.telp.focus();
  21.  return false;
  22.  }
  23.  }
  24.  return (true);
  25.  }
  26.  </script>
  27. </head>
  28. <body>
  29.  
  30. <form method="post" action="aksi.php" onsubmit="return validasi_input(this)">
  31. <p>Telp/Hp : <input name="telp" type="text"></p>
  32. <p><input name="" type="submit" value="Submit"></p>
  33. </form>
  34.  
  35. </body>
  36. </html>
Advertisement
Add Comment
Please, Sign In to add comment