- 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-26-2025 07:10 AM
it's there.
Sees somebody messed up the catalog client script form in your instance.
This is how it looks OOTB, set that field as ALL from list layout in that case
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
‎06-05-2025 03:01 AM
Everything is functioning as expected; however, the user has requested that the mobile number field retain its value even after an incorrect entry. To accommodate this, I removed the below mentioned line responsible for clearing the field. As a result, when an invalid value is entered, the field retains the incorrect input and displays an error message. However, during form submission, the invalid value is still being accepted, and an RITM is being created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 03:11 AM
Would you mind marking my response as correct if it helped?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 03:15 AM
I've marked the response as correct, but could you please assist with the issue mentioned above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 03:21 AM
you can use onSubmit to stop the form submission
function onSubmit() {
var value = g_form.getValue('mobile_number').replace(/\s/g, '');
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'
);
return false; // Prevents form submission
}
return true; // Allows submission
}
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