we must make validation for the email field to be sure that the email which input by the user is an invalid email , and we can do that as bellow
E.G .
let us say that we have email field as
email = fields.Char(string="Email")
then we can make validation by adding the function bellow
@api.constrains('email')
def _validate_email(self):
for rec in self:
if self.email and not tools.single_email_re.match(rec.email):
raise Warning(_("Please enter a valid email address."))
return True
def _validate_email(self):
for rec in self:
if self.email and not tools.single_email_re.match(rec.email):
raise Warning(_("Please enter a valid email address."))
return True
* to make this function work we must import tool and exceptions as bellow
from odoo.exceptions import ValidationError
from odoo import api , fields, exceptions, tools, models,_
No comments:
Post a Comment