javascript - how to get response from a function and validate another function in jquery -


when click button want validate 2 functions 1 one , functions validateemail(email); validatemobile(mobile); trying far , code when click getotp button

$('.getotp').click(function(e) { e.preventdefault(); var response;  var email=$('#email').val(); validateemail(email);  if(response=true){   var mobile=$('#mob').val(); validatemobile(mobile);}}); 

my emailvalidation function is

function validateemail(email){  var emailreg = new regexp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); var valid = emailreg.test(email);   if(!valid)  {       $('.errornotice').text('email address not valid');       response=false;    } else {     response=true; } }//email validate function 

and mobile validation function is

function validatemobile(mobile){     //check mobile number  if(mobile=='') {     $('.errornotice').removeclass('nodisplay');     $('.errornotice').text('mobile number can not empty');     e.preventdefault(); } else if(mobile.tostring().length>10 || mobile.tostring().length<10 ) {     $('.errornotice').removeclass('nodisplay');     $('.errornotice').text('mobile number must 10 digit');     e.preventdefault(); } //send otp else {     e.preventdefault();     $.ajax({         type:'post',         url:"otp.php",         data:{mob:mobile},         success: function(data){              e.preventdefault();             $('.errornotice').text('check mobile , enter otp');              }//success           })//ajax }//else }//mobile validate function 


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -