This article will help us to validate Email field on Partner form.
First of all, we need to understand argument of _constraints.
_constraint has list of arguments in which
1. Method is name,
2. Warning/Error message and
3. List of field name.
Method will be fire based on, change of field value given as third argument in _constraint.
Now we need to set constraint for Email field.
Here is code for constraint.
_constraints = [
(_validate_email, 'Please enter a valid email address.', ['email']),
]
Here is code for method.
@api.multi
def _validate_email(self):
for partner in self:
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", partner.email) == None:
return False
return True
NOTE:
Warning/Error message will be populate, only when method will return False.
I hope you like this article. Share your views to improve content. Happy Learning !!!
First of all, we need to understand argument of _constraints.
_constraint has list of arguments in which
1. Method is name,
2. Warning/Error message and
3. List of field name.
Method will be fire based on, change of field value given as third argument in _constraint.
Now we need to set constraint for Email field.
Here is code for constraint.
_constraints = [
(_validate_email, 'Please enter a valid email address.', ['email']),
]
Here is code for method.
@api.multi
def _validate_email(self):
for partner in self:
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", partner.email) == None:
return False
return True
NOTE:
Warning/Error message will be populate, only when method will return False.
I hope you like this article. Share your views to improve content. Happy Learning !!!