Integer Field Validation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-07-2022 12:14 AM
Hi All,
I have a Integer field "u_productive _time". I want to have validation onchange of value in such a way that it should not accept decimal value. Example - If user enters 2.10r 4.5 any decimal value . it should throw an error and it should allow only value as 1to 999.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-07-2022 12:25 AM
Hi @Roshani ,
This Solution should Help you
https://www.servicenow.com/community/developer-forum/integer-validation/m-p/2227007/page/2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-07-2022 12:28 AM
Hello,
Read below article
And then add entry like below
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-07-2022 12:45 AM
Hello @Roshani
Please check with below regex in your client script or Variable validation regex:
^([1-9][0-9]{0,2})$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-07-2022 12:58 AM
Hello,
Please use the below onchange client script to only allow numbers between 1 to 999 without decimal.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regexp = /^(?:1|[1-9]{1}[0-9]{1,2})$/;
if(!regexp.test(newValue)) {
alert('Please enter a Integer between 1 and 999');
g_form.clearValue('u_productive _time','');
}
}
Please mark answer correct/helpful based on Impact