Posted By

ryarwood on 06/13/12


Tagged

form validation dreamweaver if


Versions (?)

Dreamweaver Form Validation w/ Extra Statements


 / Published in: JavaScript
 

  1. function MM_validateForm() { //v4.0
  2.  
  3. var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  4.  
  5. //email confirmation
  6. //if (document.contactForm.communitySet.value == "No") {
  7. //errors+='- Please select a community.\n';
  8. //}
  9.  
  10. //normal macromedia form validation
  11. for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
  12. if (val) { fn=val.alt; nm=val.name; if ((val=val.value)!="") {
  13. if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  14. if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  15. } else if (test!='R') { num = parseFloat(val);
  16. if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  17. if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  18. min=test.substring(8,p); max=test.substring(p+1);
  19. if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  20. } } } else if (test.charAt(0) == 'R') errors += '- '+fn+' is required.\n'; }
  21. } if (errors) alert('The following error(s) occurred:\n'+errors);
  22. document.MM_returnValue = (errors == '');
  23.  
  24. }

Report this snippet  

You need to login to post a comment.