- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:10 AM
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
this is a mobile phone and still shows a valid phone
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 07:31 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:17 AM
Hello @Jeck Manalo,
The GlideElementPhoneNumber is helpful for basic phone number validation, but it doesn't distinguish between types of phone numbers (e.g., business vs. mobile) out of the box.
You can use regular expressions to validate business phones. Please share how business phones are looking like and formatted on your side, I can help with regular expression validation.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:23 AM
usually its written with this country code + area code (location).
- +63: Country code for the Philippines
- 2: Area code for Metro Manila
- 8866 : Local subscriber number
- then last 4 digits for the number of the user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:33 AM
it's better to have your own logic and regular expression for validating rather than using the OOTB one
Something like this in onChange client script
var phoneNumber = g_form.getValue('phone_number'); // Replace 'phone_number' with your field name
// Define the regex pattern for the phone number
var pattern = /^\+63 2 8866 \d{4}$/;
// Validate the phone number
if (!pattern.test(phoneNumber)) {
g_form.showFieldMsg('phone_number', 'Invalid phone number format. Expected format: +63 2 8866 XXXX', 'error');
g_form.clearValue('phone_number'); // Clear the field if invalid
} else {
g_form.hideFieldMsg('phone_number');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader