Validation Regex that accepts Uppercase, space and special characters.

ID NOBLE
Tera Expert

Can somebody please help me with validation Regex that accepts or allows uppercase letters, numbers, space, and special characters only such as: !@#$%&*_-,

 

How can I achieve this please? Thanks for your continuous support.

1 ACCEPTED SOLUTION

debendudas
Mega Sage

Try the below regex:

/^[A-Z0-9 !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+$/g

 If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍

View solution in original post

3 REPLIES 3

debendudas
Mega Sage

Try the below regex:

/^[A-Z0-9 !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+$/g

 If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍

@debendudas Thanks, this works.

 

Although, I had to edit it by removing the first character "/" and the last two characters "/g" to make it suite and work based on my requirement. Just saying this for anyone who might want to use this solution in the future. Once again, thanks so much @debendudas 

Juhi Poddar
Kilo Patron

Hello @ID NOBLE 

 

ServiceNow provides out-of-the-box (OOTB) solutions for regex validation without requiring custom scripting.

Create a new record in Question Regular Expressions(question_regex) table with following configuration:

 

JuhiPoddar_0-1727890873574.png

 

Add this regex to catalog variable

JuhiPoddar_1-1727890873603.png

 

When an invalid input is entered, an error message is shown.

 

Just modify the regex to ^[A-Z0-9!@#$%&*_\-\s]*$ to add the special character and white space.

Additionally, to make the alphabets and numbers mandatory the regex can be modified to ^(?=.*[A-Z])(?=.*[0-9])[A-Z0-9!@#$%&*_\-\s]*$

 

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thank You

Juhi Poddar