How to set the limit in a integer field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 06:59 AM
Hi All,
I have a question how to put the limit on any integer field. Like in a field we only put the integer value but I also want to specify that field like user can only enter min 5 digit or max 7 digit numeric value. I have already written the On-change catalog client script for only entering the integer value but also want to limit the number of digits.
Request you to please help or guide.
Thanks/Utkarsh
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 07:25 AM
Try using On chnage client script as below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
var newVal = parseInt(newValue, 10);
if (newVal < 100 || newVal > 200) {
g_form.showFieldMsg('field_name', 'Values must be between 100 and 200', 'error');
}
}
Mark helpful or correct based on impact
Regards,
Priyanka A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2020 04:55 AM
Hi Utkarsh,
if you are still looking for solution to this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2020 08:30 AM
Hi Utkarsh,
You can achieve it using RegExp. I've tested it, and it should work.
var field=g_form.getValue('variablename');
var validate=new RegExp("^(\\d{5,7})$");
if(validate.test(field))
//returns true if it the "field" value is is a digit, whose length is anything between 5-7.
Mark ✅ Correct and click Helpful if this satisfies your requirement.