Merge pull request #2105 from expsa/samir-aladawi-fix-email-validation
[FIX] partner_custom: add email regex
This commit is contained in:
commit
4ed2c2e6dd
|
|
@ -4,6 +4,7 @@ from odoo import models, fields, api, exceptions, tools, _
|
|||
from datetime import datetime, date, timedelta
|
||||
from odoo.exceptions import Warning, ValidationError
|
||||
from odoo.modules.module import get_module_resource
|
||||
import re
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
|
@ -55,7 +56,7 @@ class ResPartner(models.Model):
|
|||
|
||||
@api.constrains('email')
|
||||
def _check_email_format(self):
|
||||
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
||||
for record in self:
|
||||
if record.email:
|
||||
if '@' not in record.email or not record.email.endswith('.com'):
|
||||
raise ValidationError(_("The email address must contain '@' and end with '.com'."))
|
||||
if record.email and not re.match(email_regex, record.email):
|
||||
raise ValidationError(_("Invalid email address."))
|
||||
Loading…
Reference in New Issue