Phone Number Validation
# 📖tutorials
m
The only pre-requirement here is that you have a good understanding of what a valid phone number looks like in your country. In my example I'm doing portuguese phone numbers, they have 9 numbers and start with either 91 93 or 96. Ask for a phone number and store it in a variable, in my case the variable is called phoneNumber. Also, create a boolean, in my case, isValidNumber. workflow.isValidNumber = false; // Remove any spaces or non-digit characters const cleanNumber = workflow.phoneNumber.replace(/\D/g, ''); const validPrefixes = ['96', '93', '91']; // Check if the cleaned number has a valid length and starts with right prefix if (cleanNumber.length !== 9 || !validPrefixes.some(prefix => cleanNumber.startsWith(prefix))) { workflow.isValidNumber = false; }else workflow.isValidNumber = true; Then check the value of the isValidNumber boolean and do what you want with it
b
awesome work - thank you for sharing!
c
Thank you @melodic-memory-3602 !🚀
f
Awesome!
m
thank you guys!
b
thanks for this. A quick question - when i change the prefix to use 01, 07, etc only the 0 in the 01 is recognized in the number count of 9. if i use 07 or 06 it drops the 0 and fails validation. is there a way to get around this?
s
Thanks, it works 💐
c
Glad to hear this!
j
can we have one for email valdiation ?
so if the email is valid it gets saved in a tabel or google sheet
if its not then it not going to be saved
just an idea
p
This helped me to validate the phone number in my project, thanks alot @melodic-memory-3602
j
@wooden-library-69399
w
Thanks alot @jolly-policeman-82775
Thanks @melodic-memory-3602
j
Np man
b
Hi bro I'm sorry for bothering you but I don't really understand what I have to do to input this phone verification in my chatbot. May you please share a template so as I try to get inspired for my bot ? thanks
2 Views