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
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
Odoo Mail Sending Limit
Solved
|
|
2
Dec 23
|
11993 | |
|
0
Oct 23
|
33 | ||
|
3
Oct 23
|
787 | ||
|
1
Oct 23
|
569 | ||
|
1
Aug 23
|
978 |