Web Form Email Field Validation

I created the doctype and the web form with an email field which is Data type and in the option field i typed in it “Email” in order to use the default email validation but it is not working whatever the entered data is it get through and gets saved how can i solve this? thanks a lot in advance

1 Like

I am having the same issue. Here is the code I am using under client script of the webform:

frappe.web_form.validate = () => {
    if (!(frappe.utils.validate_type(frappe.web_form.get_value("email_address"), "email"))) {
        frappe.msgprint('Invalid email address');
        return false;
    }
}

After clicking on submit, the ‘Invalid email address’ message appears with the "Saved Successfully’ dialog box right behind it and the form is submitted with incorrect email address. I would like for the submission to not happen unless a valid email address is entered.

Any help would be appreciated.

1 Like

frappe.throw is required to stop the process. msgprint will just print

Or you can simply put “Email” in Options for the email address field and it will be validated successfully.

cc: @kennethsequeira is the genius who taught me this today :clap:

2 Likes

The first issue posted by @Abdallah_Korraim is that he can not use the Email in Option to validate.

Use frappe.msgprint with raise_exception=True as one of the args will stop the saving of form just like frappe.throw.

It works smoothly in V13. I’d request you to upgrade and try again.

This email validation for webform worked well in earlier version of version-12 (sorry I don’t check and remember until which version of version 12.x).
But it seems stop working at least in the last version of version-12.

The return false; seem to not stop the form from submitting. This bug still persist in v14.

how can i add validation to phone input to control phone length i want lengtj to be more than 8 numbers?? any help?

i use jquery this work

$(document).ready(function() {
  $('button[type=submit]').click(function(event) {
    event.preventDefault();
    let data = frappe.web_form.get_values();
    if(data){
        if (!(frappe.utils.validate_type(data.email, "email"))) {
            frappe.throw("Invalid Email Address");
        }else{
            $('form').submit();
        }
    }
  });
});
2 Likes