- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 08:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 05:13 AM
then use this
// onChange Client Script for mobile_number field
// Type: onChange
// Field name: mobile_number
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// Remove all spaces for validation
var value = newValue.replace(/\s/g, '');
// Regex: Must start with '+', followed by exactly 10 digits, nothing else
var regex = /^\+\d{10}$/;
if (!regex.test(value)) {
g_form.showFieldMsg(
'mobile_number',
'Please enter a valid mobile number: must start with "+" and be followed by exactly 10 digits.',
'error'
);
g_form.clearValue('mobile_number');
} else {
g_form.hideFieldMsg('mobile_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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 08:53 AM
Could you please elaborate and provide more information?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 09:06 AM
Hi @Ria
You can try below script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var length = g_form.getValue('u_mobile_phone').length;
if(length != 10)
{
g_form.clearValue('u_mobile_phone');
g_form.showErrorBox('u_mobile_phone', 'enter 10 digits only');
}
else
{
g_form.setValue('u_mobile_phone', '+' + newValue);
}
}
You can refer to the scripts mentioned in these threads :
https://www.servicenow.com/community/itsm-forum/help-in-phone-number-formatting-in-variable/m-p/5704...
https://www.servicenow.com/community/developer-articles/field-validation-regular-expressions/ta-p/23...
Mark as correct and helpful if it solved your query.
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 01:11 AM
Hi @harish41
I checked the script above, and it currently doesn't accept the plus sign. I would like to include a plus sign followed by 10 digits.
Regards,
Riya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 09:09 AM - edited ‎05-22-2025 09:10 AM
Hi @Ria,
Please share more details, where you are configuring this variable setting.
However, you can configure the Regular Expression and use this regex with phone number variable.
/^[+-]?\d{10}$/
Let us know if this works for you.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution