Hi,
We have the phone numbers formatted as (123) 456-7890;ext=12
I would like to show an error if the phone number contains any other non numbers or special characters. Please advise the code on how to achieve this?
Thanks.
Hi,
We have the phone numbers formatted as (123) 456-7890;ext=12
I would like to show an error if the phone number contains any other non numbers or special characters. Please advise the code on how to achieve this?
Thanks.
In this case, the regex will be \(\d{3}\) \d{3}-\d{4};ext=\d{1,10}
See the regex in action: regex101.com/.../3
Thanks Xavier, this really helps. In the case where if I would like to allow the phone number EXTENSION maximum from 1 to 10 numbers after ext=, how do I do that in regex? Please advise
For example, I want the user to allow the phone number (123) 456-7890;ext=12345 or (123) 456-7890;ext=123412 or (123) 456-7890;ext=12345897
Hi,
You can create or use a PCF. See pcf.gallery/.../ for example. A regular expression like \(\d{3}\) \d{3}-\d{4};ext=\d{2} should works.
Or you can write a javascript code that check the format with a regex:
const invalidPhoneNumberNotif = "INVALID_PHONE_NUMBER_FORMAT"; function checkPhoneNumberFormat(execCtx) { const formCtx = execCtx.getFormContext(); const phoneNumberAttr = execCtx.getEventSource(); const phoneNumberCtrl = formCtx.getControl(phoneNumberAttr.getName()); const phoneNumber = phoneNumberAttr.getValue(); const phoneNumberRegex = /\(\d{3}\) \d{3}-\d{4};ext=\d{2}/; if (phoneNumber != null && !phoneNumberRegex.test(phoneNumber)) { phoneNumberCtrl.setNotification("Phone number format must be (123) 456-7890;ext=12", invalidPhoneNumberNotif); } else { phoneNumberCtrl.clearNotification(invalidPhoneNumberNotif); } }
Add this javascript function to the "on change" event of your phone number fields. Ensure to check "Pass the execution context as first parameter".
If ;ext=12 is optional, you will need to adapt the regex. You can test/adapt the regex here: regex101.com/.../1
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156