The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Only allow positive values in a currency field, not allow zero?

Chandler2
Tera Guru

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!

5 REPLIES 5

Prince Arora
Tera Sage
Tera Sage

@Chandler2 

 

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.

 

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.

@Chandler2 ,

 

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.

 

Priyanka0402
Mega Sage
Mega Sage

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