OpenERP Email validation

前端 未结 4 1957
萌比男神i
萌比男神i 2021-01-25 13:26

Please let me know , how to prevent record getting saved when user enters invalid email address. Right now system displays warning message for invalid email address which is a

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 13:46

    You need to modify your create write and validate functions.I hope your validateemail method is correct.Whenever the re.match is None, then warning will be showed.

    def  ValidateEmail(self, cr, uid, ids, email):
        if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) == None:
            raise osv.except_osv('Invalid Email', 'Please enter a valid email address')
        return True
    
    def create(self, cr, uid,values,context=None):
        if 'email' in values:
            self.ValidateEmail(cr,uid,[],values['email'])
        res = super(latest_base,self).create(cr,uid,values,context=context)
        return res
    
    def write(self, cr, uid, ids, values, context=None):
        if 'email' in values:
            self.ValidateEmail(cr,uid,ids,values['email'])
        res = super(latest_base, self).write(cr, uid, ids, values, context=context)
        return res 
    

提交回复
热议问题