How restrict # and * characters in single line text field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 06:44 AM
Hi,
i need to restrict #, * characters in a single line text field , can someone help me?
Thanks.
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 06:52 AM
Hello,
There's several ways to do this, but you can create onChange client script that simply looks at that field to validate, such as:
var string = g_form.getValue('field_name');
if (string.indexOf("#") > -1 || string.indexOf("*") > -1) {
alert("Please do not use the # or * characters");
g_form.clearValue('field_name');
}
You can also use regex, etc.
You did not state if this was a variable or not, thus I didn't mention anything regarding variable regex specifically. My method above will work, as well as reviewing the use of basic regex as well will work.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 03:49 AM
Hi,
the above mentioned code snippet is not working so can you share a regex for this case(like excluding # and *).
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 08:55 AM
Hello,
The above mentioned code does work. You should use it in an onChange client script, choosing the correct field to execute on...and it works just fine:
You can certainly give me more feedback and an example of how you're trying to use it, but please don't imply that what I've offered doesn't work, when it does.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 06:53 AM
Hi
Variable Regex should help you.
Here is a thread which has 2 approaches along with the code :https://community.servicenow.com/community?id=community_question&sys_id=f3fde89bdbb9c8905ed4a851ca96...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep