- 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 02:42 AM
Hey @Krishna101 ,
Use below Regular Expression:
^\$[1-9]{1}(?:\d{0,2}(?:,\d{3})*)?\.\d{2}$
Using the site below, you can test whether your input validates against your regular expression.
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 04:31 AM
Hi Ashish,
Its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 04:55 AM - edited 10-30-2024 04:58 AM
@Krishna101 , The regex pattern is working for me. Please see the screenshots below.
If I enter incorrect input, it doesn't accept it.
When I enter input according to the field message, it is accepted.
Also its accepting your given input as $4,000,000.00
Could you please validate your input on the site I shared earlier? If it doesn’t work, could you provide additional input examples?
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:02 AM
Please find here