To restrict special characters in a Single Line Textbox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2025 03:16 AM
in Choice box -To restrict special characters in a Single Line Textbox?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2025 03:27 AM
Hi @Community Alums
You can use client scripts with Regex to validate user input. Please share more details about where you're planning to implement this validation.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2025 03:30 AM - edited 08-18-2025 03:31 AM
If you know what all characters to restrict, a simp[le way would be using a client script as below
var string = g_form.getValue('field_name');
if (string.indexOf("#") > -1 || string.indexOf("*") > -1) { //here its restricting # and *, tyou can add more
alert("Please do not use the # or * characters");
g_form.clearValue('field_name');
}
Below is a more elaborate solution using regex
Solved: Restriction validation for single line text field - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2025 04:00 AM
Hi @Community Alums ,
You can create an onChange client script that triggers whenever the value of the Single Line Text field changes.
var regex = /[!@#$%^&*(),.?":{}|<>]/g;
if (regex.test(newValue)) {
alert('Special characters are not allowed.');
g_form.setValue(control.name, oldValue);
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/