// JavaScript Document //field validation ----------------------------------------- function fieldCheck(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } //----------------------------------------------------------- //email validation ------------------------------------------- function emailCheck(email, alerttxt) { if (email == '' || email == null) { alert(alerttxt); return false; } else { //alert(email); var at=email.indexOf('@'); var dot=email.lastIndexOf('.'); var atpos=email.lastIndexOf('@'); var emlen=email.length; if (at<1||dot-at<2||atpos+1==emlen||dot+1==emlen||emlen-dot<3) { alert(alerttxt); return false } } return true; } //----------------------------------------------------------------- //for phone number check ------------------------------------------ function phoneCheck(pnum, alerttxt) { if (pnum == '' || pnum == null) { alert(alerttxt); return false; } else { var phchar="1234567890 -_+.()"; for (i=0;i<=pnum.length;i++) { if(phchar.indexOf(pnum.charAt(i))==-1) { alert(alerttxt); return false ; } } } return true ; } //---------------------------------------------------------------- //for number check------------------------------------------------ function numCheck(pnum, alerttxt) { if (pnum == '' || pnum == null) { alert(alerttxt); return false; } else { var phchar="1234567890"; for (i=0; i<=pnum.length; i++) { if(phchar.indexOf(pnum.charAt(i))==-1) { alert(alerttxt); return false ; } } } return true ; } //----------------------------------------------------------------- //Radio butoon check boxes --------------------------------------- function checkBox(chkname, alerttxt) { alert(chkname); var inputs = document.getElementsByTagName("input"); a=0; for(var t = 0;t < inputs.length;t++){ if(inputs[t].type == "checkbox" && inputs[t].checked == true && inputs[t].name===chkname) { a=1; } } //alert(a) ; if(a==0) { alert(alerttxt); return false ; }else { return true ; } } //---------------------------------------------------------------- //For radio boxes function radio(radname,alerttxt) { //alert(chkname); var inputs = document.getElementsByTagName("input"); a=0; for(var t = 0;t < inputs.length;t++){ if(inputs[t].type == "radio" && inputs[t].checked == true && inputs[t].name===radname) { a=1; } } //alert(a) ; if(a==0) { alert(alerttxt); return false ; }else { return true ; } } //----------------------------------------------------------------- //form validation ------------------------------------------------- /*function validate_form(thisform) { //alert(thisform) ; with (thisform) { if (fieldCheck(name,"Name must be filled out!")==false) {name.focus();return false;} if (fieldCheck(add1,"Address must be filled out!")==false) {add1.focus();return false;} if (fieldCheck(city,"City must be filled out!")==false) {city.focus();return false;} if (fieldCheck(state,"State must be filled out!")==false) {state.focus();return false;} if (numCheck(zip.value,"Zip must be filled out with numbers!")==false) {zip.value=''; zip.focus(); return false;} if (fieldCheck(country,"Country must be filled out!")==false) {country.focus();return false;} if (phoneCheck(phone.value,"Phone must be filled out!")==false) {phone.value=''; phone.focus(); return false;} if (emailCheck(email.value,"Valid email must be filled out!")==false) {email.value=''; email.focus();return false;} if (fieldCheck(ccname,"Credit card holder name must be filled out!")==false) {ccname.focus();return false;} if (fieldCheck(cctype,"Select the type of credit card!")==false) {cctype.focus();return false;} if (isValidCreditCard(ccnum.value, cctype.value, "Credit card number must be valid!")==false) {ccnum.value=''; ccnum.focus();return false;} if (fieldCheck(ccmonth,"Expiry month must be selecte!")==false) {ccmonth.focus();return false;} if (fieldCheck(ccyear,"Expiry year must be selecte!")==false) {ccyear.focus();return false;} if (isExpiryDate(ccmonth.value, ccyear.value, "Card was expired. Sorry!")==false) {shipping.focus();return false;} if (radio('order[]', "Check your order!")==false) {document.getElementById('order').focus();return false;} if (fieldCheck(shipping,"Select your shipping!")==false) {shipping.focus();return false;} } } */ //---------------------------------------------------------------- function createElements(cntry) { //alert(cntry) ; document.getElementById('austate').style.visibility='hidden'; if(cntry == 'AU'){ //document.getElementById('austate').innerHTML = '' ; //document.getElementById('austate').innerHTML = 'jfsadfsadjfsl' ; document.getElementById('austate').style.visibility='visible'; } } //Credit card validation------------------------------------------- function isValidCreditCard(ccnum, type, alerttxt) { // alert(ccnum); //alert(type); if (type == "Visa") { // Visa: length 16, prefix 4, dashes optional. var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/; } else if (type == "MasterCard") { // Mastercard: length 16, prefix 51-55, dashes optional. var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/; } else if (type == "Amex") { // American Express: length 15, prefix 34 or 37. var re = /^3[4,7]\d{13}$/; } else if (type == "Diners") { // Diners: length 14, prefix 30, 36, or 38. var re = /^3[0,6,8]\d{12}$/; }else if (type == "Disc") { // Discover: length 16, prefix 6011, dashes optional. var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/; } if (!re.test(ccnum)) { alert(alerttxt); return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.split("-").join(""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. var checksum = 0; for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) { checksum += parseInt(ccnum.charAt(i-1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (var i=(ccnum.length % 2) + 1; i expiry.getTime()) { alert(alerttxt) return false; } else { //alert("success") return true; } } //---------------------------------------------------------