- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 05:55 AM
I modifying a module we created in Service Now and I've added two integer fields one of which I want to restrict to 2 characters and the other to four, additionally I want the four character field to display a 1234 and not 1,234.
Can anyone suggest an easy way to do this please as I can't track it down in the WIKI?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 07:06 AM
Hi Angus,
You don't need the number validation if you're using an integer field as the dictionary entry already validates that, so we only need to worry about the length. Here's an onchange script that returns an alert and clears out the value of the field if it's not 4 digits.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if (newValue.toString().length != 4) {
alert("Please enter a 4 digit number");
g_form.setValue('fieldname', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 07:36 AM
Thanks Harish for the help.
I have stuck with Brad's script as it cleared the field if I entered more than four digits.
Thanks anyway