$(document).ready(function(){ let fullname=/[a-zA-Z][a-zA-Z ]*$/; var phoneno = /[0-9]$/; var emailvalidation=/^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/; let mobile=''; let name=''; let email=''; let pathName=window.location.pathname.split('-')[0]; $('#cf-name').off('change').change((evt)=>{ if(fullname.test(evt.target.value)){ $('#cf-name').empty().append(evt.target.value); } else{ if(evt.target.value.length<1){ $('#cf-name').empty().append(''); } else{ alert("Please enter valid name") } } }) $('#cf-email').off('change').change((evt)=>{ $('#cf-email').empty().append(evt.target.value.toLowerCase()) }) $('#cf-mobile').off('change').change((evt)=>{ if(phoneno.test(evt.target.value)){ if(evt.target.value.length<11){ $('#cf-mobile').empty().append(evt.target.value) } else{ alert("Only Enter 10 Digit"); } } else{ if(evt.target.value.length<1){ $('#cf-mobile').empty() } else{ alert("Please enter valid contact number") } } }) $('.submit').click((evt)=>{ evt.preventDefault(); name=$('#cf-name').text(); email=$('#cf-email').text(); mobile=$('#cf-mobile').text(); var response = grecaptcha.getResponse(); if(name!='' && email!='' && mobile!='' && response.length!='' ){
if(mobile.length==10){ if(emailvalidation.test(email.toLowerCase())){
const request={ method:'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({'first_name':name,'email':email,'mobile':mobile,'lpage':pathName.replace('/',''),'l_page':window.location.pathname.replace("/","")}) } fetch('https://moneysukh.com:8443/crm',request) .then(response=>{ if(response.ok){ response.json().then(json=>{ if(json.dta.contact!=undefined){ sendMsg(request) } else{ alert("email id already exists") }
}) } }) .catch(e=>{ console.log(e); }) } else{ alert("Please enter valid email") } } else{ alert("Please enter 10 digit") }
} else{ alert("Please enter the all field value") }
}) const sendMsg=(request)=>{ fetch('https://moneysukh.com:8443/res/send-mail',request) .then(response=>{ if(response.ok){ response.json().then(json=>{ window.location=window.location.href; }) } }) .catch(e=>{ console.log(e); }) } })