- 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
11-05-2024 01:44 AM
Hi ,
not working
Please suggest
Thanks
Krishna
- 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
11-05-2024 03:48 AM
Hi Ashish,
Its working.Thanks for your help.
Thanks
Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 04:13 AM
@Krishna101 , It’s wonderful that the solution is working! If you need anything else or have more questions, just let me know. Happy to help!
Thanks,
Ashish