Only allow positive values in a currency field, not allow zero?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 05:10 AM
I have a currency field and want to only allow positive values in the field. It should also not allow zero or negative values to be entered.
Please help.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 05:16 AM
You can write a onchange client script on the field and mention below scritpt:
var pattern = /^[0-9.,]*$/;
if(!pattern.test(newValue))
{
alert('Please enter a postive number.');
g_form.clearValue('YOUR_FIELD_NAME');
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 05:28 AM - edited 04-17-2023 05:32 AM
hi @Prince Arora No, it is not working. The alert is showing even if I enter 2 or 5 or 20 or 0 anything. Also, the field value is not being cleared.
Actually, If I check value in snutil, it is EUR;0.0. So, it always has to be EUR.
Maybe we have to include this in the regex as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 05:56 AM
Please try this regex:
var pattern = /^(EUR:)[1-9]\d*[.][1-9]\d*$/;
if(!pattern.test(newValue))
{
alert('Please enter a postive number.');
g_form.clearValue('YOUR_FIELD_NAME'); //please provide your field backend name , dont copy the complete code
}
If it doesn't work for you, please provide the test cases for which you want the regex,
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 05:23 AM
Hi @Chandler2
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//make sure they only enter numbers, comma, decimal, or dollar sign
var integer = /^[0-9.,]*$/;
if(!integer.test(newValue))
{
alert('Please enter a valid number.');
g_form.clearValue('amount');
}
//make sure they do not enter just zero
if(newValue == 0)
{
alert('Please enter a non-zero value.');
g_form.clearValue('amount');
}
}
I hope this helps.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Priyanka