Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Integer Field Validation

Roshani
Tera Expert

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.

4 REPLIES 4

Community Alums
Not applicable

Musab Rasheed
Tera Sage

Hello,

Read below article

https://www.servicenow.com/community/developer-articles/field-validation-regular-expressions/ta-p/23...

And then add entry like below

MusabRasheed_0-1665127690169.png

 

Please hit like and mark my response as correct if that helps
Regards,
Musab

Mahendra RC
Mega Sage

Hello @Roshani 

Please check with below regex in your client script or Variable validation regex:

^([1-9][0-9]{0,2})$

Saurav11
Kilo Patron
Kilo Patron

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