- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 03:28 AM
Hi Team
I am facing a issue in Phone number field type
I want to display an Error message when the Phone number field allows special characters and spaces.
regards
Rushikesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 08:24 AM
Hello @Community Alums
Could you please try below script and check if this works for you
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var regex = /^[0-9]+$/; // Regular expression to allow only numbers
if (!regex.test(newValue)) {
g_form.showErrorBox('phone_number', 'Phone number should only contain numbers');
}
}
Thanks,
Amarjeet Pal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 11:23 AM
Hello @Community Alums,
Please refer to this : https://www.servicenow.com/community/spm-forum/how-can-i-restrict-spaces-and-special-characters-in-a-string/m-p/976894
@Community Alums, Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.
Thank you!