- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have a SN catalog form that has a phone number field. The validation must ensure the below -
- Phone number must start with plus sign (+)
- There must be a space after the country code
Example: For Australia, format should be: +61 458690289, For India, +91 7620243813
How to achieve this kind of functionality on client script validation, so that the moment phone number field is typed in and user moves to next field, it shows either a error or success message on the catalog form
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
try this in onChange catalog client script on that variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Clear previous messages
g_form.hideFieldMsg('phone_number', true);
// Allow empty if the field is optional
if (!newValue) {
return;
}
// +<countrycode><space><number>
var phonePattern = /^\+\d{1,3}\s\d{6,14}$/;
if (!phonePattern.test(newValue)) {
g_form.showFieldMsg(
'phone_number',
'Phone must be in format +<country code> <number>, e.g. +61 458690289 or +91 7620243813.',
'error',
true
);
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
try this in onChange catalog client script on that variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Clear previous messages
g_form.hideFieldMsg('phone_number', true);
// Allow empty if the field is optional
if (!newValue) {
return;
}
// +<countrycode><space><number>
var phonePattern = /^\+\d{1,3}\s\d{6,14}$/;
if (!phonePattern.test(newValue)) {
g_form.showFieldMsg(
'phone_number',
'Phone must be in format +<country code> <number>, e.g. +61 458690289 or +91 7620243813.',
'error',
true
);
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
44m ago
Thanks a lot @Ankur Bawiskar . worked perfect