- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 08:17 PM
i'm creating a new single line field to be set as integer in a catalog item. how do i set limit to this field so that user can only fill in only up to '9'?
thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 08:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 08:36 PM
Hi @Hafila Hatta ,
Please try on-change catalog client script on the single variable with below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regexp =/^\d{0,9}$/;
if(!regexp.test(newValue)){
alert('Please enter numeric value below 9');
g_form.setValue('total','');
}
}
to make exactly 9 digits: then replace the regex with
/^\d{4}$/
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks,
BK

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 08:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 09:12 PM
thanks! this is helpful and save me from creating scripts!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 08:59 PM
Hi there,
Consider using Regex Variable Validation for this.
- 2019-04-22 - Article - Service Portal Catalog Items: Regex Field Validation
- 2019-08-14 - Article - Regexes for Catalog Items Variable Validation, part 2
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field