- 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 04:59 AM
Field should accept input with exactly 10 digits and an one '+' prefix and show an error if the digit count exceeds 10.
- 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 06:54 AM
Could you please let me know why changes are not reflecting on portal but changes are reflecting on backend?
Regards,
Riya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 06:57 AM
Did you set UI type - ALL for your client script?
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:02 AM