Phone Number E164 Field type OOTB Scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 01:16 AM
Hi,
I tried to find the Scripts that work in backend for logic/validations for Phone Number (E164) but had no luck in finding them. As I am trying to implement the same validations and mechanism in the old Phone Number (string) field. And Customer is insisting on not changing the field type to Phone Number (E164) and provide the same validations on old Phone number field. Does anyone have any idea on this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 01:26 AM
Since the customer does not want to change the field type to Phone Number (E164), you will need to manually implement validation logic on the old Phone Number (string) field.
Client script - Client Side Validation
function onSubmit() {
var phoneNumber = g_form.getValue('your_phone_field_name');
// Regular expression for E.164 format validation
var e164Pattern = /^\+?[1-9]\d{1,14}$/;
if (!e164Pattern.test(phoneNumber)) {
g_form.addErrorMessage('The phone number must be in E.164 format.');
return false;
}
return true;
}
Business Rule - server side validation
(function executeRule(current, previous /*null when async*/) {
// Regular expression for E.164 format validation
var e164Pattern = /^\+?[1-9]\d{1,14}$/;
if (!e164Pattern.test(current.your_phone_field_name)) {
gs.addErrorMessage('The phone number must be in E.164 format.');
current.setAbortAction(true);
}
})(current, previous);
Regards,
Sid