Skip to content

Commit 1eae7e3

Browse files
authored
Allow positive and decimal values and ignore other values in string field in ServiceNow (#1955)
* Create Allow positive and decimal values.js * Create readme.md
1 parent 409df5e commit 1eae7e3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || newValue == '') {
3+
return;
4+
}
5+
6+
var regex = /^[0-9]+(\.\d{1,2})?$/; // Allows positive integers or decimals
7+
8+
if (!regex.test(newValue) || newValue <= 0) {
9+
g_form.setValue('amount', '');
10+
g_form.showFieldMsg('amount', 'Please enter a amount greater than zero with decimals .Decimals are allowed here.', 'error');
11+
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Purpose of this script:
2+
3+
It matches positive numbers (integers or decimals)
4+
It does not match 0 or 0.0 (i.e., it excludes non-positive numbers).
5+
6+
So this regex is used when you want to allow only positive (> 0) integer or decimal values.
7+
It will give us the field message error if anyone tries to enter anything apart from the allowed values

0 commit comments

Comments
 (0)