How to validate if the input is a valid phone number only denied it if its a mobile phone

Jeck Manalo
Tera Guru

I am using the GlideElementPhoneNumber since its an OOTB to validate if phone is valid.

 

My question is how can we validate if the user input a mobile phone number format into business phone and make it as invalid ?

 

this is a business phone and its ok

 

 

JeckManalo_0-1744272525007.png

 

 

this is a mobile phone and still shows a valid phone

 

JeckManalo_1-1744272525010.png

 

 

my thinking is i will use a field in a user field then input the format for Business Phone and validate it if its written the same in business phone field then its valid instead of using OOTB.

 

2 ACCEPTED SOLUTIONS

Hi @Jeck Manalo,
Please create OnChange Catalog Client Script for your business phone field and use below script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var phone = newValue.trim();
    var validBusinessFormat = /^\+63\s2\s8866\s\d{4}$/;

    if (!validBusinessFormat.test(phone)) {
        g_form.showFieldMsg('phone', 'Invalid business phone format. Expected format: +63 2 8866 XXXX', 'error');
    } else {
        g_form.hideFieldMsg('phone', true);
    }
}

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

View solution in original post

@Jeck Manalo 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Correct ankur, I was expecting to use a field to input all business phone of every country and then compare it using onchange if its match then its a valid phone number.

@Jeck Manalo 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader