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

How to write a currency regex that accepts positive value only?

lisaO
Giga Contributor

Hi, 

Currently I am using this regex for my currency validation. It accepts numeric value in 0.00 format (with 2 decimals). However, how can I modify the regex further to accept only positive currency? At the moment, I can still enter eg. -12.00 as the currency. 

Separately, how do i automatically convert the currency once entered by user to the format with a 1000 seperator? (eg, if user enter 1200.00, with onchange, the field will automatically change to 1,200.000?

Thank you in advance!

1 REPLY 1

Omkar Mone
Mega Sage

Hi 

You can write this code in onChange client script of yours 

 

function onChange(control, oldValue, newValue, isLoading)
{
//Type appropriate comment here, and begin script below
var a = newValue;
var b = new RegExp("-");
if (b.test(a))
{
g_form.showErrorBox ("u_fcy_bookings_product","Bookings cannot be negative");
g_form.setValue("your decimal field","");
}

 


}

Also, as it is a decimal field type, it will not be converted from 12.00 to 12.

 

Hope this helps.

 

Regards,

Omkar Mone