Allow String type variable to accept only integers

Rocky5
Kilo Sage

Hello Devs,

 

We have a string type variable in catalog item. And we want that variable to accept only integers greater than 8. I am using below regex in my script and it does not accept any number greater than 9. But I want that variable to accept any number greater than 8 but no less than 8. 

 

regex: /^[8-9]*$/

 

How can I achieve that?

 

Thanks,

Rocky.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Rocky5 

this regex worked for me

^(?:[9]|\d\d\d*)$

AnkurBawiskar_0-1716389235354.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Rocky5 

this regex worked for me

^(?:[9]|\d\d\d*)$

AnkurBawiskar_0-1716389235354.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

This one fails with string more than 1 zeros.

 

Screenshot 2024-05-22 at 9.42.48 PM.png

 

 

Sandeep Rajput
Tera Patron
Tera Patron

@Rocky5 Try using the following regular expression.

 

^(?:[9]|^[1-9]\d+)$

It passes the 00 test.

 

Screenshot 2024-05-22 at 9.39.08 PM.png

VarunS
Kilo Sage

@Rocky5 

Try 

/^(?:[9]|\d{2,})$/