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-07-2022 10:28 PM
Hi
Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 03:53 AM
If #,* are not allowed then what else is allowed?
based on that you can create RegEx
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 06:29 AM
Hi Ankur,
only #and * are not allowed and the rest can be accepted.
Thank You.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 04:08 AM
Hi
You need to create an onChange Client Script -
- Field Name (Variable Name in case of Catalog Items): Your field/variable name
- Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } //Hide all messages if any g_form.hideAllFieldMsgs(); var testNameRegex = /^.+.(\*|#)+.+.$/; //Test the RegEx; If * or # is found then true else false if(testNameRegex.test(newValue)) { //Error message goes here } else { //Add required logic or remove else loop if not required } }
Please try the above code and let me know if you still face any issue.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik