JAVASCRIPT   39

validateForm

Guest on 10th June 2022 01:32:58 AM

  1. function validateForm()
  2. {
  3. var x=document.forms["myForm"]["fname"].value;
  4. if (x==null || x=="")
  5.   {
  6.   alert("First name must be filled out");
  7.   return false;
  8.   }
  9. }
  10.  
  11. function validateForm()
  12. {
  13. var x=document.forms["myForm"]["email"].value;
  14. var atpos=x.indexOf("@");
  15. var dotpos=x.lastIndexOf(".");
  16. if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  17.   {
  18.   alert("Not a valid e-mail address");
  19.   return false;
  20.   }
  21. }

Raw Paste


Login or Register to edit or fork this paste. It's free.