- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 10:14 AM
Hi Guys,
I created a catalog item with few variables. In that i have a User name variable (of type String).
It should allow only letters but not special characters like @ # % ^ etc..
How can i do this?
Regards,
Vijay
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 10:24 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = new RegExp("^[a-zA-Z0-9]*$");
if(!regex.test(newValue)){
alert('Incorrect username');
g_form.setValue('u_user_name','');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 10:22 AM
Below link should help
https://www.codexworld.com/how-to/check-special-characters-using-javascript/
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 10:24 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = new RegExp("^[a-zA-Z0-9]*$");
if(!regex.test(newValue)){
alert('Incorrect username');
g_form.setValue('u_user_name','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 06:42 AM
Hi,
I am new to Servicenow. I want to create a client script on Change. I want to validate whether the User ID starts with "THDM". How can i restrict those string using script. Can someone help?