Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

What is the correct Regular Expression for preventing a space in a variable?

Zhane
Tera Contributor

I am trying to prevent any spaces on a variable and set up a regex for this and it's not working

find_real_file.png

1 ACCEPTED SOLUTION

Shane41
ServiceNow Employee

Hi Zhane,

I would recommend changing your regex to ^\S+$

Have you added the regex to the variable itself? (Note:It will only work on particular variable types)

There is a field on the variable that needs to be set to your new regex record - Validation regex (you may need to add this to the form layout)

find_real_file.png

I created the updated regex (^\S+$) in my own instance and it works after I added it to a single line text variable

find_real_file.png

Hope this helps,

Shane

View solution in original post

2 REPLIES 2

Shane41
ServiceNow Employee

Hi Zhane,

I would recommend changing your regex to ^\S+$

Have you added the regex to the variable itself? (Note:It will only work on particular variable types)

There is a field on the variable that needs to be set to your new regex record - Validation regex (you may need to add this to the form layout)

find_real_file.png

I created the updated regex (^\S+$) in my own instance and it works after I added it to a single line text variable

find_real_file.png

Hope this helps,

Shane

Sai Kumar B
Mega Sage

@Zhane 

Can you try with the below regex?

Regex - ^\S*$

find_real_file.png

 

find_real_file.png