- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 01:03 AM
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.
Thanks in Advance
Krishna
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 02:16 AM
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 06:06 AM
Its not allowing the format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 06:52 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 07:07 AM
Hi Chavan,
Thanks for your help, but no luck its not working
Thnaks
Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 07:12 AM - edited 10-30-2024 07:13 AM
@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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 07:30 AM
Hi Chavan,
Please find the error
Please find my configuration