lp.jQuery(function($) {l;
var ruleID = 'phoneNumberValidate';
var field = 'phone';
var message = 'Phone number status: invalid';
var rules = module.lp.form.data.validationRules[field];
$.validator.addMethod(ruleID, function(value, field) {
function ajax(url, num) {
return new Promise(function(resolve, reject) {
$.ajax({
url: url,
type: 'post',
data:{"data":num},
});
});
}
ajax(actualUrl, value).then(function(response){
var parsedData = JSON.parse(response);
var status = parsedData.data.status;
console.log(status);
if(status == "invalid"){
return false;
console.log("False returned");
}
}).catch(function() {
// An error occurred
});
}, message);
rules[ruleID] = true;
});
Hello, This is code that i used to validate phone number. The way i intend it to work is it should make ajax request to an API endpoint and on base of that true/false response it should validate the phone input. If the response is true then number is validate and client will be able to submit form else form will not be submitted. But it’s not working as intended. Can anyone here tell me what i’m doing wrong here?? Is anything wrong with my ajax request ?? A bundle of thanks