diff --git a/Client-Side Components/Client Scripts/Allow positive and decimal values/Allow positive and decimal values.js b/Client-Side Components/Client Scripts/Allow positive and decimal values/Allow positive and decimal values.js deleted file mode 100644 index 435b3245a5..0000000000 --- a/Client-Side Components/Client Scripts/Allow positive and decimal values/Allow positive and decimal values.js +++ /dev/null @@ -1,13 +0,0 @@ -function onChange(control, oldValue, newValue, isLoading) { - if (isLoading || newValue == '') { - return; - } - - var regex = /^[0-9]+(\.\d{1,2})?$/; // Allows positive integers or decimals - - if (!regex.test(newValue) || newValue <= 0) { - g_form.setValue('amount', ''); - g_form.showFieldMsg('amount', 'Please enter a amount greater than zero with decimals .Decimals are allowed here.', 'error'); - - } -} diff --git a/Client-Side Components/Client Scripts/Allow positive and decimal values/readme.md b/Client-Side Components/Client Scripts/Allow positive and decimal values/readme.md deleted file mode 100644 index 1fbdd451c1..0000000000 --- a/Client-Side Components/Client Scripts/Allow positive and decimal values/readme.md +++ /dev/null @@ -1,7 +0,0 @@ -Purpose of this script: - -It matches positive numbers (integers or decimals) -It does not match 0 or 0.0 (i.e., it excludes non-positive numbers). - -So this regex is used when you want to allow only positive (> 0) integer or decimal values. -It will give us the field message error if anyone tries to enter anything apart from the allowed values diff --git a/Specialized Areas/Regular Expressions/Positive int with 2 decimals/Allow positive and decimal values.js b/Specialized Areas/Regular Expressions/Positive int with 2 decimals/Allow positive and decimal values.js new file mode 100644 index 0000000000..927c4b98ab --- /dev/null +++ b/Specialized Areas/Regular Expressions/Positive int with 2 decimals/Allow positive and decimal values.js @@ -0,0 +1,25 @@ +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading || newValue == '') { + return; + } + + // Regex: allows positive integers or decimals with up to two decimal places + var regex = /^[0-9]+(\.\d{1,2})?$/; + + // Regex explanation: + // ^ : Start of string + // [0-9]+ : One or more digits (whole number part) + // (\.\d{1,2})? : Optional decimal part + // \. : Literal decimal point + // \d{1,2} : One or two digits after the decimal + // $ : End of string + // This pattern matches positive integers or decimals with up to two decimal places + + // Replace 'amount' with the actual field name this script is attached to + var fieldName = "amount"; + + if (!regex.test(newValue) || newValue <= 0) { + g_form.clearValue(fieldName); + g_form.showFieldMsg(fieldName, 'Please enter a value greater than zero. Decimals are allowed (up to two places).', 'error'); + } +} diff --git a/Specialized Areas/Regular Expressions/Positive int with 2 decimals/readme.md b/Specialized Areas/Regular Expressions/Positive int with 2 decimals/readme.md new file mode 100644 index 0000000000..f29f720805 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Positive int with 2 decimals/readme.md @@ -0,0 +1,10 @@ +## Numeric Field Validation Script + +This script validates numeric input in a form. It is used to ensure that values entered in fields like amount or price are properly formatted. + +### Validation Rules + +- Only positive numbers are allowed +- Decimals are allowed, up to two digits +- Zero or negative values are not accepted +- Invalid input will clear the field and show an error message