JezK
Edit File: validations.js
function validateUploadedImage(e) { // alert("hai"); var fileName = document.getElementsByName("image")[0]["files"][0]["name"]; // var fileNamesArr = fileName.split(".") // console.log(fileName) // var extensions = ["jpg", "jpeg", "png"]; // let count = 0; let preview = document.getElementById("preview") // extensions.map(val => { // if (fileNamesArr[1] == val) { // count++; // return false; // } // }) // var status= fileName.endsWith("jpg"); if(fileName.endsWith("jpg") || fileName.endsWith("jpeg") || fileName.endsWith("png")){ var reader = new FileReader(); reader.onload = function() { var output = document.getElementById('imagePreview'); output.src = reader.result; }; reader.readAsDataURL(e.target.files[0]); }else{ alert(imgVal); $("#formUpload").val(""); return false; } // if (count == 0) { // alert("please upload an image in .jpeg , .jpg or .png extensions"); // return false; // } else { // var reader = new FileReader(); // reader.onload = function() { // var output = document.getElementById('imagePreview'); // output.src = reader.result; // }; // reader.readAsDataURL(e.target.files[0]); // } } function validateCustomerDetails() { let customer_name = document.getElementById('customer_name').value; let email = document.getElementById('customer_email').value; let password = document.getElementById('customer_password').value; // console.log(customer_name + email +contact+ address+SgiftmentAddress+city) // alert("test"); $('.error').html(''); if (customer_name == '') { $('.customer_name_error').html(nameRequire); $('#customer_name').focus(); return false; } else if (email == '') { $('.customer_email_error').html(emailRequire); $('#customer_email').focus(); return false; } else if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($("#customer_email").val()) == false) { $('.customer_email_error').html(passValid); $('#customer_email').focus(); return false; } else if (password == '') { return true; } else if (password != '' && /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test($("#customer_password").val()) == false) { $('.password_error').html(passwordTypeAlert); $('#customer_password').focus(); return false; } } function checkUpdatedEmailOrPhone(emailOrPhone, id, type) { $.ajax({ type: "POST", url: "ajax.php", data: { "process": "checkUpdatedEmailExistsOrNot", "id": id, "emailOrPhone": emailOrPhone, "type": type }, success: function(data) { if (data.state == "success") { $('.error').html(''); if (data.result == 1 && type == 1) { $('.subadmin_email_error').html('Email already exists'); document.getElementById('admin_email').value = ''; document.getElementById('admin_email').focus(); } else if (data.result == 1 && type == 2) { $('.subadmin_phone_error').html('Phone number already exists'); document.getElementById('admin_phone').value = ''; document.getElementById('admin_phone').focus(); } } else { // if api.php returns failure, display error } }, error: function(jqXHR, textStatus, errorThrown, data) { // error handling }, dataType: "json" }); } function checkExistsOrNot(recVal, type) { // alert("Hello"); if (recVal != '' && type != '') { let dataVal = recVal; let key = dataVal.replace(/ /g, "***"); var receivedData = { requestedValue: key, type: type }; $.ajax({ type: "POST", url: "ajax.php", data: { "process": "checkExistsOrNot", "data": JSON.stringify(receivedData) }, success: function(data) { if (data.state == "success") { $('.error').html(''); if (data.result == 1 && type == 1) { $('.subadmin_email_error').html('Email already exists'); document.getElementById('admin_email').value = ''; document.getElementById('admin_email').focus(); } else if (data.result == 1 && type == 2) { $('.subadmin_phone_error').html('Phone number already exists'); document.getElementById('admin_phone').value = ''; document.getElementById('admin_phone').focus(); } } else { // if api.php returns failure, display error } }, error: function(jqXHR, textStatus, errorThrown, data) { // error handling }, dataType: "json" }); } } function validateSubAdmin() { // alert("Hello"); let admin_name = document.getElementById('admin_name').value; let admin_email = document.getElementById('email').value; let admin_phone = document.getElementById('admin_phone').value; let admin_country = document.getElementById('admin_country').value; let admin_address = document.getElementById('admin_address').value; let admin_city = document.getElementById('city').value; $('.error').html(''); if (admin_name == '') { // alert("Hello"); $('.subadmin_name_error').html(nameReq); $('#admin_name').focus(); return false; } else if (admin_email == '') { $('.subadmin_email_error').html(emailReq); $('#admin_email').focus(); return false; } else if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(admin_email) == false) { $('.subadmin_email_error').html(valPass); $('#admin_email').focus(); return false; } else if (admin_country == '') { $('.subadmin_country_error').html(coutryVal); $('#admin_country').focus(); return false; } else if (admin_city == '') { $('.city_error').html(cityVal); $('#admin_city').focus(); return false; } else if (admin_phone == '') { $('.subadmin_phone_error').html(phoneVal); $('#admin_phone').focus(); return false; } else if (admin_phone.length < 5 || admin_phone.length > 15) { $('.subadmin_phone_error').html(phoneLenval); $('#admin_phone').focus(); return false; } else if (admin_address == '') { $('.subadmin_address_error').html(addVal); $('#admin_address').focus(); return false; } } function validateSubAdminEdit() { // alert("Hello"); let admin_name = document.getElementById('admin_name').value; let admin_email = document.getElementById('admin_email').value; let admin_phone = document.getElementById('admin_phone').value; let admin_country = document.getElementById('admin_country').value; let admin_address = document.getElementById('admin_address').value; let admin_city = document.getElementById('city').value; $('.error').html(''); if (admin_name == '') { // alert("Hello"); $('.subadmin_name_error').html(nameReq); $('#admin_name').focus(); return false; } else if (admin_email == '') { $('.subadmin_email_error').html(emailReq); $('#admin_email').focus(); return false; } else if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(admin_email) == false) { $('.subadmin_email_error').html(valPass); $('#admin_email').focus(); return false; } else if (admin_country == '') { $('.subadmin_country_error').html(coutryVal); $('#admin_country').focus(); return false; } else if (admin_city == '') { $('.city_error').html(cityVal); $('#admin_city').focus(); return false; } else if (admin_phone == '') { $('.subadmin_phone_error').html(phoneVal); $('#admin_phone').focus(); return false; } else if (admin_phone.length < 5 || admin_phone.length > 15) { $('.subadmin_phone_error').html(phoneLenval); $('#admin_phone').focus(); return false; } else if (admin_address == '') { $('.subadmin_address_error').html(addVal); $('#admin_address').focus(); return false; } } function checkPhone(e) { var key = e.keyCode || e.charCode; if (key == 13 || key == 43 || (key >= 48 && key <= 57) || key == 8 || key == 46) { return true; } else { return false; } } function validateLogin(){ //~ alert("Login"); } function passwordGeneration(){ let $=jQuery; let password=document.getElementById('password').value; let cnfrmPassword = document.getElementById('cnfrmPassword').value; if(password==""){ $('.password_error').html(passwordAlert); $('#password').focus(); return false; } else if (cnfrmPassword == '') { $('.cnfrmPassword_error').html(reqConfirmPass); $('#cnfrmPassword').focus(); return false; } else if (password != '' && /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test($("#password").val()) == false) { $('.password_error').html(passwordTypeAlert); $('#password').focus(); return false; } else if (cnfrmPassword != '' && /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test($("#cnfrmPassword").val()) == false) { $('.cnfrmPassword_error').html(passConTypeAlert); $('#cnfrmPassword').focus(); return false; } else if (password != cnfrmPassword) { $('.cnfrmPassword_error').html(pasAndConf); $('#cnfrmPassword').focus(); return false; } } function changePassword() { let $ = jQuery; let old_password = document.getElementById('oldPassword').value; let password = document.getElementById('password').value; let cnfrmPassword = document.getElementById('cnfrmPassword').value; $('.error').html(''); if (old_password == '') { $('.old_password_error').html(oldPassAlert); $('#oldPassword').focus(); return false; } else if (password == '') { $('.password_error').html(passwordAlert); $('#password').focus(); return false; } else if (password != '' && /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test($("#password").val()) == false) { $('.password_error').html(passwordTypeAlert); $('#password').focus(); return false; } else if (cnfrmPassword == '') { $('.cnfrmPassword_error').html(reqConfirmPass); $('#cnfrmPassword').focus(); return false; } else if (cnfrmPassword != '' && /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test($("#cnfrmPassword").val()) == false) { $('.cnfrmPassword_error').html(passConTypeAlert); $('#cnfrmPassword').focus(); return false; } else if (password != cnfrmPassword) { $('.cnfrmPassword_error').html(passMisMatchAlert); $('#cnfrmPassword').focus(); return false; } } function checkExistsOrNotcon(recVal,type) { if(recVal!='' && type!='') { if(type==5) { if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(recVal) == false) { $('.email_error').html('Enter valid Email'); document.getElementById('email').value=''; document.getElementById('email').focus(); return false; } } let dataVal=recVal; console.log(dataVal); let key=dataVal.replace(/ /g,"***"); var receivedData = { requestedValue: key, type:type}; $('#submit').prop('disabled', true); $.ajax({ type: "POST", url: "./../securedajax.php", data: {"process": "checkExistsOrNot", "data":JSON.stringify(receivedData)}, success: function(data) { if (data.state == "success") { /* alert(data.result); alert(type);*/ // alert(data.result); $('.error').html(''); if(data.result==1 && type==7) { $('.email_error').html(emailValid); document.getElementById('email').value=''; document.getElementById('email').focus(); } if(data.result==3 && type==7) { $('.email_error').html(eamilAlrValid); document.getElementById('email').value=''; document.getElementById('email').focus(); } } else { // if api.php returns failure, display error } $('#submit').prop('disabled', false); }, error: function(jqXHR, textStatus, errorThrown, data) { // error handling $('#submit').prop('disabled', true); }, dataType: "json" }); } } function checkExistsOrNotcon2(recVal,type) { if(recVal!='' && type!='') { if(type==5) { if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(recVal) == false) { $('.email_error').html(phonAlrValid); document.getElementById('email').value=''; document.getElementById('email').focus(); return false; } } let dataVal=recVal; let key=dataVal.replace(/ /g,"***"); var receivedData = { requestedValue: key, type:type}; $('#submit').prop('disabled', true); $.ajax({ type: "POST", url: "./../securedajax.php", data: {"process": "checkExistsOrNot", "data":JSON.stringify(receivedData)}, success: function(data) { if (data.state == "success") { $('.error').html(''); if(data.result==1 && type==8) { $('.subadmin_phone_error').html('Phone number already exists'); document.getElementById('admin_phone').value=''; document.getElementById('admin_phone').focus(); } } else { // if api.php returns failure, display error } $('#submit').prop('disabled', false); }, error: function(jqXHR, textStatus, errorThrown, data) { // error handling $('#submit').prop('disabled', false); }, dataType: "json" }); } } function checkLength(value,type){ // if(type==1 && value.length>25){ // // $('.first_name_error').html('firstname should not be greater than 25 charecters'); // alert('Company_name should not be greater than 25 charecters') // $('#company_name').focus(); // return false; // } if(type==6 && value.length>25){ alert('Name should not be greater than 25 charecters') $('#admin_name').focus(); return false; } } function testimonialValidation() { let $ = jQuery; $(".error").html(""); var tname = $('#tname').val(); var tdescrip = $('#tdescrip').val(); var image = $('#previewImage img').attr('src'); if(tname == "") { $('.tname_error').html('Please enter Name'); $('#tname').focus(); return false; } if(tdescrip == "") { $('.tdescrip_error').html('Please enter Description'); $('#tdescrip').focus(); return false; } if(image == "") { $('.image_error').html('Please select image'); $('#fileupload').focus(); return false; } }