Pinakin Nayi
Pinakin Nayi

Reputation: 125

e-mail validation in Openerp?

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

Answers (3)

Shelton
Shelton

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

Shelton
Shelton

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

kushalbhaktajoshi
kushalbhaktajoshi

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

Related Questions