How to set number range in Single-line text variable type in service catalog?

Leo Cris Ramos
Giga Expert

Hi, Everyone.

I used single line text variable and changed the validation regex to Number.

However, I'm not sure how to set a number range, for example the maximum person can be in a room is only 25.

Can someone help?

 

find_real_file.png

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Leo,

This has no limit on the number of digits.

If you want to restrict or set the range you will have to use a OnChange Client Script:-

The logic you should use is below:

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return }

var regExTest = /^[1-9][0-9,]*$/;

 if(!regExTest.test(newValue)){  

 

  alert("Please enter valid characters");     g_form.setValue('urfieldname', '');  

} }

 

Please mark my answer as Correct & Helpful, if applicable.

Thanks

Sandeep

 

View solution in original post

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi.

How about changing the variable type to Numeric scale instead?

Otherwise you need to perform some additional logic (onchange script) to validate that the number entered is max 25.

I need to set it from 1-999 🙂

Then I would go with @Mark Roethof solution, create a custom variable regex.

To try and learn about regex, you can try this page: https://regexr.com/

Mark Roethof
Tera Patron
Tera Patron

Hi there,

So your question is a Regex for 0 to 25? Or is your question different?

If 0 - 25:

\b([0-9]|1[0-9]|2[0-5])\b

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn