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
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
Odoo Mail Sending Limit
Đã xử lý
|
|
2
thg 12 23
|
14801 | |
|
0
thg 10 23
|
33 | ||
|
3
thg 10 23
|
788 | ||
|
1
thg 10 23
|
569 | ||
|
1
thg 8 23
|
2520 |