正規表現を使用して検証する
import re
from osv import osv,fields
class crm_lead_inherit(osv.osv):
_name = _inherit = 'crm.lead'
def create(self,cr,uid,vals,context=None):
if 'mobile' in vals and vals['mobile']:
if re.match("^[0-9]*$", vals['mobile']) != None:
pass
else:
raise osv.except_osv(_('Invalid Mobile No'),_('Please enter a valid Phone Number'))
return super(crm_lead_inherit, self).create(cr, uid,vals, context=context)
def write(self,cr,uid,ids,vals,context=None):
if 'mobile' in vals and vals['mobile']:
if re.match("^[0-9]*$", vals['mobile']) != None:
pass
else:
raise osv.except_osv(_('Invalid Mobile No'),_('Please enter a valid Phone Number'))
return super(crm_lead_inherit, self).write(cr, uid,ids,vals, context=context)
crm_lead_inherit()