Pawan Kumar Sharma
Pawan Kumar Sharma

Reputation: 1168

Remove space between mobile number odoo 13

I want to remove space and '-' between the mobile number in odoo v13. Currently my mobile number format like this '+977 960-2582808'. From this format i want to remove space and '-'. This is mobile field in res.partner table with widget="phone".

expected result: +9779602582808

I am trying below code:

login_mobile = fields.Char()
mobile_sanitized = fields.Char(string='Mobile Number')
   
@api.onchange("login_mobile")
def onchange_device_id(self):
    print('aaaaaaaaaaaaa')
    self.mobile_sanitized = self.login_mobile.strip(' ')

Thanks in advance.

Upvotes: 0

Views: 1304

Answers (1)

Paxmees
Paxmees

Reputation: 1590

.strip() removes characters from beginning and end of the string. EDIT Use regular expression:

import re
self.mobile_sanitized = re.sub('[^0-9+]','', self.login_mobile)

Upvotes: 1

Related Questions