Merge pull request #2105 from expsa/samir-aladawi-fix-email-validation

[FIX] partner_custom: add email regex
This commit is contained in:
SamirLADOUI-sa 2025-01-13 08:26:56 +01:00 committed by GitHub
commit 4ed2c2e6dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -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."))