Skip to main content

Hello there,

I want to validate phone number field based on Lookup Api JSON response. I have used the below code but this is not working. Anyone can help me to work it?


window.ub.form.customValidators.usPhoneNumber = {
isValid: function(value) {
var country_code;
var uName="API Key SID";
var passwrd="API Key Secret";
var apiUrl = 'https://lookups.twilio.com/v1/PhoneNumbers/'+value;
var auth = btoa(uName+":"+passwrd);
$.ajax({
type: 'GET',
url: apiUrl,
headers: {
"Authorization": "Basic " + auth
},
success : function(data) {
country_code = data.country_code;
console.log(country_code);
},
});
return country_code === 'US';
},
message: 'Please enter a valid US Phone Number',
};
window.ub.form.validationRules.cellphone_number.usPhoneNumber = true;


Hey @Bayzid_Tee!
Β 

πŸš€ We have a brand new, complete solution for adding Country Codes and Flags to Unbounce! You can simply validate your phone number field with this solution!

πŸ†“ FREE Version:


πŸ’Ž PRO Powerful Version:
πŸ‘‰ https://www.grooic.com/cfu-unbounce

Β 

πŸ‘€Β Check Out the Live Preview Here:

🌐 https://www.grooic.com/cfu-preview/

Β 

🀝 If you have any questions or need support, feel free to reach out to us on WhatsApp:Β πŸ’¬ +1 917 900 3111

Thanks,


Reply