- 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-23-2025 02:37 AM
Did you get a chance to check the solution I shared above?
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 12:17 AM
I checked the above script and it's accepting more then 10 digits and no error message is displayed.
Regards,
Riya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 12:20 AM
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// Remove all spaces from the input for validation
var value = newValue.replace(/\s/g, '');
// RegEx Explanation:
// ^\+? : Optional '+' at the start
// \d{10,} : At least 10 digits
// $ : End of string
var regex = /^\+?\d{10,}$/;
// Count of '+' signs
var plusCount = (value.match(/\+/g) || []).length;
// Validation checks:
// 1. Only one '+' at the start (if any)
// 2. At least 10 digits
// 3. Only digits allowed after optional '+'
if (
!regex.test(value) || // Fails the main format
(plusCount > 1) || // More than one '+'
(plusCount === 1 && value.charAt(0) !== '+') // '+' not at start
) {
g_form.showFieldMsg(
'mobile_number',
'Please enter a valid mobile number: minimum 10 digits, only one "+" allowed at the start, digits only.',
'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 12:36 AM
I checked the above script and it's accepting more then 10 digits again and no error message is displayed.
Regards,
Riya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 12:55 AM
In your question you said minimum 10 numbers so it will accept more than 10 as well
What's your actual business requirement?
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