i'm testing some validation functions for the phone field to avoid others characters than numbers from 0 to 9.
def valide_tel(self, cr, uid, ids, context=None):
record = self.browse(cr, uid, ids)
pattern = "^\+?[0-9]*$"
for data in record:
if re.match(pattern, data.phone) == None:
I tested the regex on pythex.org with success, but the problem is that when no phone number is entered, Odoo complains about ValidationError: expected string or buffer.
What can i do to have this working?
When there is no value entered in the phone field, it will take it as False, and regular expression will work on string only.
So, either you make your phone field as mandatory to the user or before implementing 'if condition' check if the value of data.phone is not False .
Hope this will help you!
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 1/11/16, 10:35 AM|
|Seen: 1217 times|
|Last updated: 1/12/16, 9:04 AM|