Field validation: Regular Expressions : Stop Invalid Characters

Aditya Banka2
Tera Guru

Hello All,

I have a requirement where I need to validate a field in service catalog. It shouldn't allow special characters as '`~!@#$%^&*()|+=?;:'",<>{} []\/

Also it shouldn't allow

\W = Anything that isn't a word character (including punctuation etc)

\s = Anything that is a space character (including space, tab characters etc)

also it shouldn't allow the domain @xx.com

I tried creating a new variable validation regex with regular expression as [a-zA-Z0-9]{1,20} and using it under Validation Regex.

With this it is not allowing any special characters as such, but how can I incorporate \W \s and domain @xx.com, in the same regular expression.

 

2 REPLIES 2

Aman Kumar S
Kilo Patron

You can use below regex:

^([a-zA-Z0-9_\-\.]+)@domain\.com$

Follow below link:

https://community.servicenow.com/community?id=community_article&sys_id=ebcf2b6edbd7d0103daa1ea668961...

Best Regards
Aman Kumar

Hi @Aditya Banka 

Is your query resolved?

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar