How to stop the form submission from onchange Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 01:00 AM
Hi Experts,
I have a requirement when user enters invalid email pattern and tries to save the form, it should abort the form submission.
Below is my script Please correct it to make to work.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var email = g_form.getValue('email');
if (!email || email.trim().length <= 0)
return true;
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (re.test(email)) {
return true;
}
g_form.showFieldMsg('email', 'Invalid Email', 'error');
return false;
}
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 01:33 AM
Hi,
This should work for you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var email = g_form.getValue('email');
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var isValidFormat = re.test(email);
if (!isValidFormat) {
g_form.showFieldMsg('email', 'Invalid Email', 'error');
}
}
Please mark my answer as helpful/correct depending on its impact.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 06:32 AM
This didn't work for me. Do you have any idea why?
It doesn't style like an error should or the docs say. If I use 'info' instead of 'error', it styles fine and works as expected for info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 06:58 AM
Hi,
Try with below script.