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 new file mode 100644 index 0000000000..435b3245a5 --- /dev/null +++ b/Client-Side Components/Client Scripts/Allow positive and decimal values/Allow positive and decimal values.js @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000000..1fbdd451c1 --- /dev/null +++ b/Client-Side Components/Client Scripts/Allow positive and decimal values/readme.md @@ -0,0 +1,7 @@ +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