- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 12:58 AM
Hi, i want to restrict special characters in string field. And I used the below script , it is restricting spaces also, can anyone help on how to achieve this, without restricting spaces.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below.
var regex = new RegExp("^[a-zA-Z0-9]*$"); //no special characters
var str = g_form.getValue('title_of_the_usecase');
var len = str.length;
if(!regex.test(newValue))
{
alert('Please enter only letters');
g_form.setValue('title_of_the_usecase','');
}
}
Regards,
kalyani
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 01:20 AM
Complete script.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
var regex = /^[a-zA-Z0-9\s]*$/;
if (!regex.test(newValue)) {
g_form.clearValue('title_of_the_usecase');
g_form.showFieldMsg('title_of_the_usecase', "Please only enter letters.", "error");
}
}
}
Execution results:
case 1: OK
case 2: Special character. Entered "This has a special character $ in the sentence"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 01:07 AM
Hi kalyani,
Use "\s"
var regex = new RegExp("^[a-zA-Z0-9\s]*$"); //no special characters

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 01:09 AM
Hi Kalyani,
Use this
/^[0-9a-zA-Z]*$/;
Regards
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 01:20 AM
Complete script.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
var regex = /^[a-zA-Z0-9\s]*$/;
if (!regex.test(newValue)) {
g_form.clearValue('title_of_the_usecase');
g_form.showFieldMsg('title_of_the_usecase', "Please only enter letters.", "error");
}
}
}
Execution results:
case 1: OK
case 2: Special character. Entered "This has a special character $ in the sentence"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 01:23 AM
Thank you