Odoo Help

Parth Patel (pat)
On 11/6/17, 8:23 AM

Hello Pawan,
Specific about your python condition :  

if rec.is_mobile and len(rec.is_mobile) != "^[0-9]{10}$" :
I Could not understand why you need to compare regex string with length, as it going to directly compare the string only not regex output.
So, rather you can directly do something like this :
if rec.is_mobile and len(str(rec.is_mobile)) != 10 :

Hii @Parth, Your code upto 10 digits work well, But after 10 digits it shows error "The following fields are invalid: " also warning message change into error when using character and other type words. I want that warning show else than 10 digits in any condition.

Thanks for help.

SunArc Technologies, Pawan Sharma
on 11/7/17, 12:09 AM

Hi Pawan, The Error warning 'The following fields are invalid: ' is due to you are using is_mobile as an Integer field and it can store max 10 digits, more than that it will show error. To, avoid this you can take Char field insted.

Just sake of information :

If you are about to develope something in odoo you can even use the default phone validation module provided by odoo. Where you have to just define phone widget in xml view.

<field name="phone" widget="phone"/>

And make sure module 'phone_validation' will install. This module will validate the phone number according to the country selected.

Parth Patel (pat)
on 11/7/17, 12:34 AM

Thanks parth, Now error message problem solved, but there is still one problem is that it take 10 values they might be integer, character, comma and etc. But i want only 10 integer values else validation. So, how i solve this problem for only integer 10 numbers?

SunArc Technologies, Pawan Sharma
on 11/7/17, 1:07 AM

Hello Pawan, For that you can make use of your regex like this,

import re

pattern = re.compile("^[0-9]{10}$")

if pattern.match(string):

return true


return false

Parth Patel (pat)
on 11/7/17, 1:22 AM

Thanks parth work with following code:



def _onchange_phone_number(self):

pattern = re.compile("^[0-9]{10}$")

for rec in self:

if pattern.match(rec.whats_app) and len(str(rec.whats_app)) == 10:

return True


raise ValidationError(_("Invalid Mobile No."))

SunArc Technologies, Pawan Sharma
on 11/7/17, 4:00 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 11/6/17, 2:21 AM
Seen: 1965 times
Last updated: 11/7/17, 1:07 AM