Phone Number E164 Field type OOTB Scripts

Chanpreet Singh
Tera Contributor

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

1 REPLY 1

Sid_Takali
Kilo Patron
Kilo Patron

Hi @Chanpreet Singh 

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