- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2021 06:12 AM
I need a script to validate a telephone number field that will only allow numbers and spaces (no special characters). Min 10 & max 20 characters and to show field msg and clear value if invalid value entered.
Can anyone point me in the right direction? Thanks in advance
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2021 06:35 AM
Hi,
something like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('fieldName');
var regex = /^[\d\s]{10,20}$/;
if (newValue != '' && !regex.test(newValue)) {
g_form.clearValue('fieldName');
g_form.showFieldMsg("fieldName", "Invalid phone", "error");
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2021 06:15 AM
you can make use of regular expression
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2021 06:16 AM
Hi,
What format is the phone number?
Is it US format?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2021 06:28 AM
It could be any country format so just want to restrict the number of characters to between 10 & 20 and prevent special characters being entered i.e. + and ().
This would then match the validation in our ERP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2021 06:35 AM
Hi,
something like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('fieldName');
var regex = /^[\d\s]{10,20}$/;
if (newValue != '' && !regex.test(newValue)) {
g_form.clearValue('fieldName');
g_form.showFieldMsg("fieldName", "Invalid phone", "error");
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader