Question Regular Expression Currency

Krishna101
Tera Contributor

Hi Community,
I have cretaed variable name is Amount and type as single line text. I have created Question Regular Expression for this variable to all format of $12.00.
Question Regular Expression :  ^\$[0-9]+\[,]+\.?[0-9]*$
but user want to this format only to allow $4,000,000.00
How can create Question Regular Expression to allow above format. Could you please help into this.

Krishna101_0-1730275375124.png

Thanks in Advance
Krishna

1 ACCEPTED SOLUTION

Hi @Krishna101

 

Instead of creating and using a validation regex pattern, could you please try creating an onChange client script like the one below?

 

Type: onChange

Variable Name: currency (your_variable_name)

script: 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   // Regular expression to match the format $4,000,000.00
    var regex = /^\$[1-9]{1}(?:\d{0,2}(?:,\d{3})*)?\.\d{2}$/;
    
    // Get the value of the Amount field
    var currencyValue = g_form.getValue('currency');
    
    // Check if the Amount field value matches the regex pattern
    if (!regex.test(currencyValue)) {
        // If not matched, display an error message
        g_form.showFieldMsg('currency', 'Please enter the amount in the format $4,000,000.00', 'error');
    } else {
        // Clear the field message if the value matches the pattern
        g_form.clearMessages();
    }
   
}

 

 

Here are some outputs:

ashish_parab_0-1730801194453.png

ashish_parab_1-1730801251715.png

 

If this also doesn't work, try replacing the regex pattern in the script as provided in this thread. 

Let me know if it works for you!

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

View solution in original post

13 REPLIES 13

Krishna101_1-1730293576980.png

Its not allowing the format

Aniket Chavan
Tera Sage
Tera Sage

Hello @Krishna101 ,

Please give a try to the Regular Expression below and see how it works for you.

^\$[1-9]\d{0,2}(?:,\d{3})*(?:\.\d{2})?$

 

Let me know if you still face any issues with this.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket



 

Hi Chavan,
Thanks for your help, but no luck its not working
Thnaks
Krishna

 

@Krishna101  - Oh, okay! Please try this updated version. I’ve made a few slight adjustments:

 

 

^\$[1-9]\d{0,2}(,\d{3})+\.\d{2}$

 

 

This should match formats like $4,000,000.00 with commas and exactly two decimal places. Let me know if it works for you!

Hi Chavan,

Krishna101_0-1730298530479.png

Please find the error

Krishna101_1-1730298572517.png

Please find my configuration

Krishna101_2-1730298633003.png