Validate Single line text to not to allow special characters to enter

Gowtham29
Tera Expert

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

1 ACCEPTED SOLUTION

Naveen20
ServiceNow Employee
ServiceNow Employee

You can add a client script by checking the field value and adding an error message as below

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

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 Roethof
Tera Patron
Tera Patron

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

LinkedIn

Naveen20
ServiceNow Employee
ServiceNow Employee

You can add a client script by checking the field value and adding an error message as below