- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 08:29 AM
Hi Everyone,
I have single text variable name to enter name of the user in a catalog item form. I want to validate this field in such a way that, it should not allow users to accept special character '-' in that variable. If they enter such character, alert should pop up on the screen saying that special character '-' is not allowed while entering user name
for example, name should not be 'ABC - SNOW'. It should be like any 'ABC SNOW'
kindly help me to achieve this task. Thanks in advance
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 08:40 AM
You can add a client script by checking the field value and adding an error message as below

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 08:36 AM
try now
var abc = 'ABC - SNOW';
if(abc.indexOf('-') >-1){
alert(' - not allow');
}
else{
alert('allow');
}
Note: you can use indexOf() if you only want to validate '-'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 08:36 AM
Hi there,
Check out these articles I wrote on Variable Regex. These might help you a lot:
- https://community.servicenow.com/community?id=community_article&sys_id=f5b8a988db057300d82ffb2439961...
- https://community.servicenow.com/community?id=community_article&sys_id=78785137dbcbf3801cd8a345ca961...
Then you simply need the Regex code. For A to Z, there's an exact example in the second link.
No additional scripting needed!
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2019 08:40 AM