Guest User

Untitled

a guest
Aug 30th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JavaScript Document
  2. function clear_txt() {
  3.     var inputElements = document.getElementsByTagName("input");
  4.            
  5.     for (var i=0; i < inputElements.length; i++) {
  6.             if (inputElements[i].type == 'text' || inputElements[i].type == 'textarea') {
  7.                 inputElements[i].value = '';
  8.             }
  9.             if  (inputElements[i].type == 'radio') {
  10.                 inputElements[i].checked = false;
  11.             }
  12.                  
  13.      }
  14. }
  15.  
  16. function validateFrm(theForm) {
  17.   var reason = "";
  18.   var badphne=false;
  19.   var badmail=false;
  20.   var badzip=false;
  21.  
  22.   reason += validate(theForm.fname,"First Name");
  23.   reason += validate(theForm.lname,"Last Name");
  24.   reason += validate(theForm.address1,"Address");
  25.   reason += validate(theForm.city,"City");
  26.   reason += validate(theForm.state,"State");
  27.   reason += validate(theForm.company,"Company");
  28.  
  29.   badzip=validateZip(theForm.zip.value);
  30.   if(!badzip) { reason += "\t" + "Zip Code is not valid" + "\n"; theForm.zip.style.background = '#ccccff'; }
  31.   else { theForm.zip.style.background = 'White'; }
  32.  
  33.   badphne=validatePhoneNumber(theForm.phone.value);
  34.   if (!badphne) { reason += "\t" + "Phone Number is not valid" + "\n"; theForm.phone.style.background = '#ccccff'; }
  35.   else { theForm.phone.style.background = 'White'; }
  36.  
  37.   badmail=validateEmail(theForm.email.value);
  38.   if (!badmail) { reason += "\t" + "Email is not valid" + "\n"; theForm.email.style.background = '#ccccff'; }
  39.   else { theForm.email.style.background = 'White'; }
  40.  
  41.   /*
  42.   var i=0;
  43.   do{
  44.       field=theForm.billing_fname[i];
  45.       if(field.value==''){
  46.           alert("NULL FIELD");
  47.           return false;
  48.       }
  49.       i++;
  50.   }while(i<theForm.billing_fname.length);
  51.   */
  52.  
  53.   if (! theForm.billing_check.checked){
  54.       reason += validate(theForm.billing_fname,"Billing First Name");
  55.       reason += validate(theForm.billing_lname,"Billing Last Name");
  56.       reason += validate(theForm.billing_address1,"Billing Address");
  57.       reason += validate(theForm.billing_city,"Billing City");
  58.       reason += validate(theForm.billing_state,"Billing State");
  59.      
  60.       badphne=validatePhoneNumber(theForm.billing_phone.value);
  61.        
  62.       if (!badphne) { reason += "\t" + "Billing Phone Number is not valid" + "\n"; theForm.billing_phone.style.background = '#ccccff'; }
  63.       else { theForm.billing_phone.style.background = 'White'; }
  64.   }
  65.  
  66.   if (reason != "") {
  67.     alert("Please correct the following fields: \n\n" + reason);
  68.     return false;
  69.   }
  70.  
  71.   return true;
  72. }
  73.  
  74. function validatePhoneNumber(elementValue){  
  75.     var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;  
  76.     return phoneNumberPattern.test(elementValue);  
  77. }  
  78.  
  79. function validateEmail(elementValue){
  80.    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  81.    return emailPattern.test(elementValue);
  82.  }
  83.  
  84. function validateZip(elementValue){
  85.    var zipPattern = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
  86.    return zipPattern.test(elementValue);
  87.  }
  88.  
  89. function validate(fld,rsn) {
  90.     var error = "";
  91.  
  92.     if (fld.value.length == 0) {
  93.         fld.style.background = '#ccccff';
  94.         error ="\t" + rsn + "\n";
  95.     } else {
  96.         fld.style.background = 'White';
  97.     }
  98.     return error;  
  99. }
  100.  
  101. function remove_space() {
  102.    
  103.     var tbox = document.getElementById('fname');
  104.     if (tbox)
  105.     {  
  106.         var temp=tbox.value;
  107.         tbox.value = temp.replace(' ','');
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment