Reputation: 125
I want to validate email in openerp through widget. Is there any method or is there any solution. How to validate e-mail in openERP. Simply the entered email address is valid or not.
Upvotes: 2
Views: 1015
Reputation: 116
you can try this..
def onchange_email(self, cr, uid, ids, email):
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
return True
else:
raise osv.except_osv(_('Invalid Email'), _('Please enter a valid email address'))
In your view, you would define the field with the on_change event, as described in the documentation.
<field name="email" on_change="onchange_email(email)"/>
Upvotes: 2
Reputation: 116
Email validation can be done using regular expressions. Following is an eg. code.
import re
def validateEmail(email):
if len(email) > 7:
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
return 1
return 0
Upvotes: 1
Reputation: 4678
Use the following regex for the email validation
/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
Upvotes: 0