Hello,
I want to add validation for email fields and phone numbers, if the user enter text without @ validation error raise.
thank you in advance
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
I want to add validation for email fields and phone numbers, if the user enter text without @ validation error raise.
thank you in advance
Hi,
You can do the validation according to the below code:
import re
from odoo.exceptions import ValidationError
@api.model
def create(self, vals):
if vals.get('email'):
match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', vals.get('email'))
if match == None:
raise ValidationError('Not a valid E-mail ID')
if vals.get('number'):
match = re.match('\\+{0,1}[0-9]{10,12}', vals.get('number'))
if match == None:
raise ValidationError('Invalid Phone Number')
return super(MultiContacts, self).create(vals)
Regards
Hello Jenam
you can implement constrains for your model as i have done in res.partner model.
from odoo import api
from odoo.exceptions import UserError
class ResPartner(models.Model):
_inherit = "res.partner"
@api.constrains('email')
def _check_email_number(self):
for rec in self:
if rec.email and '@' not in rec.email:
raise UserError(_('Please Enter Correct Email'))
Thanks & Regards,
Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
Odoo Mail Sending Limit
Opgelost
|
|
2
dec. 23
|
14785 | |
|
0
okt. 23
|
33 | ||
|
3
okt. 23
|
788 | ||
|
1
okt. 23
|
569 | ||
|
1
aug. 23
|
2502 |