How to stop the form submission from onchange Client Script

Pravalika1
Tera Contributor

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,