- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 07:07 AM
Hi,
I have a requirement where i should not be able to enter some special characters. I tried it but it is not working. Kindly help. Please don't post links.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^[~#%&*{}:<>?/|"\–]*$/;
if(!pattern.test(newValue)){
g_form.addErrorMessage('The following characters cannot be entered' + ' ~, #, %, & , *, {, }, \, :, <, >, ?, /, |, ", –');
g_form.clearValue('outlook_distribution_group_list_name');
}
}
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 08:18 AM
try this and it will only allow a to z, A to Z and numbers
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('outlook_distribution_group_list_name');
// Regular expression to allow only alphabets and numbers
var regex = /^[a-zA-Z0-9]+$/;
if (!regex.test(newValue)) {
// Display an error message if the input is invalid
g_form.showFieldMsg('outlook_distribution_group_list_name', 'Only alphabets and numbers are allowed.', 'error');
// Clear the invalid input
g_form.clearValue('outlook_distribution_group_list_name');
}
}
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
03-18-2025 08:19 AM
Hi @J Siva , @Ankur Bawiskar , @GopikaP
I simply used this and it works.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^[a-zA-Z0-9-.,]*$/;
if(!pattern.test(newValue)){
g_form.addErrorMessage('Special characters cannot be entered');
g_form.setValue('outlook_distribution_group_list_name', '');
}
}
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 06:44 AM
Would you mind marking my response as correct if that worked for you?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 08:19 AM
Hi @J Siva , @Ankur Bawiskar , @GopikaP
I simply used this and it works.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^[a-zA-Z0-9-.,]*$/;
if(!pattern.test(newValue)){
g_form.addErrorMessage('Special characters cannot be entered');
g_form.setValue('outlook_distribution_group_list_name', '');
}
}
Regards
Suman P.