Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JavaScript Document
- function clear_txt() {
- var inputElements = document.getElementsByTagName("input");
- for (var i=0; i < inputElements.length; i++) {
- if (inputElements[i].type == 'text' || inputElements[i].type == 'textarea') {
- inputElements[i].value = '';
- }
- if (inputElements[i].type == 'radio') {
- inputElements[i].checked = false;
- }
- }
- }
- function validateFrm(theForm) {
- var reason = "";
- var badphne=false;
- var badmail=false;
- var badzip=false;
- reason += validate(theForm.fname,"First Name");
- reason += validate(theForm.lname,"Last Name");
- reason += validate(theForm.address1,"Address");
- reason += validate(theForm.city,"City");
- reason += validate(theForm.state,"State");
- reason += validate(theForm.company,"Company");
- badzip=validateZip(theForm.zip.value);
- if(!badzip) { reason += "\t" + "Zip Code is not valid" + "\n"; theForm.zip.style.background = '#ccccff'; }
- else { theForm.zip.style.background = 'White'; }
- badphne=validatePhoneNumber(theForm.phone.value);
- if (!badphne) { reason += "\t" + "Phone Number is not valid" + "\n"; theForm.phone.style.background = '#ccccff'; }
- else { theForm.phone.style.background = 'White'; }
- badmail=validateEmail(theForm.email.value);
- if (!badmail) { reason += "\t" + "Email is not valid" + "\n"; theForm.email.style.background = '#ccccff'; }
- else { theForm.email.style.background = 'White'; }
- /*
- var i=0;
- do{
- field=theForm.billing_fname[i];
- if(field.value==''){
- alert("NULL FIELD");
- return false;
- }
- i++;
- }while(i<theForm.billing_fname.length);
- */
- if (! theForm.billing_check.checked){
- reason += validate(theForm.billing_fname,"Billing First Name");
- reason += validate(theForm.billing_lname,"Billing Last Name");
- reason += validate(theForm.billing_address1,"Billing Address");
- reason += validate(theForm.billing_city,"Billing City");
- reason += validate(theForm.billing_state,"Billing State");
- badphne=validatePhoneNumber(theForm.billing_phone.value);
- if (!badphne) { reason += "\t" + "Billing Phone Number is not valid" + "\n"; theForm.billing_phone.style.background = '#ccccff'; }
- else { theForm.billing_phone.style.background = 'White'; }
- }
- if (reason != "") {
- alert("Please correct the following fields: \n\n" + reason);
- return false;
- }
- return true;
- }
- function validatePhoneNumber(elementValue){
- var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
- return phoneNumberPattern.test(elementValue);
- }
- function validateEmail(elementValue){
- var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
- return emailPattern.test(elementValue);
- }
- function validateZip(elementValue){
- var zipPattern = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
- return zipPattern.test(elementValue);
- }
- function validate(fld,rsn) {
- var error = "";
- if (fld.value.length == 0) {
- fld.style.background = '#ccccff';
- error ="\t" + rsn + "\n";
- } else {
- fld.style.background = 'White';
- }
- return error;
- }
- function remove_space() {
- var tbox = document.getElementById('fname');
- if (tbox)
- {
- var temp=tbox.value;
- tbox.value = temp.replace(' ','');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment