Skip to content

Commit e75699b

Browse files
authored
Update and rename Allow positive and decimal values.js to Allow positive and decimal values.js
Moved the file to the Regex folder. Refactored the code: - use clearValue instead of setValue ''. - fieldName to make it easier to adjust and use. - Include comment to describe the Regex
1 parent f1f5267 commit e75699b

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

Client-Side Components/Client Scripts/Allow positive and decimal values/Allow positive and decimal values.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || newValue == '') {
3+
return;
4+
}
5+
6+
// Regex: allows positive integers or decimals with up to two decimal places
7+
var regex = /^[0-9]+(\.\d{1,2})?$/;
8+
9+
// Regex explanation:
10+
// ^ : Start of string
11+
// [0-9]+ : One or more digits (whole number part)
12+
// (\.\d{1,2})? : Optional decimal part
13+
// \. : Literal decimal point
14+
// \d{1,2} : One or two digits after the decimal
15+
// $ : End of string
16+
// This pattern matches positive integers or decimals with up to two decimal places
17+
18+
// Replace 'amount' with the actual field name this script is attached to
19+
var fieldName = "amount";
20+
21+
if (!regex.test(newValue) || newValue <= 0) {
22+
g_form.clearValue(fieldName);
23+
g_form.showFieldMsg(fieldName, 'Please enter a value greater than zero. Decimals are allowed (up to two places).', 'error');
24+
}
25+
}

0 commit comments

Comments
 (0)