# Phone number validation

**URL:** https://discuss.tryton.org/t/phone-number-validation/8379
**Category:** Developer
**Created:** [March 6, 2025, 7:26pm UTC](https://discuss.tryton.org/t/phone-number-validation/8379 "2025-03-06T19:26:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [March 6, 2025, 7:26pm UTC](https://discuss.tryton.org/t/phone-number-validation/8379/1 "2025-03-06T19:26:27Z")

</div>

I have a strange behavior in proteus.  
i am trying to validate a party from CA with a phone number that tryton do not like.  
i tried :

```auto
    x = phonenumbers.parse( '819-944-2765', 'CA')
    if phonenumbers.is_valid_number(x):
        print ("phone is VALID"); # <== the phone is valid

```

but tryton says :

```auto
 Le numéro de téléphone « +33 8199442765 » du tiers « Tartempion» n'est pas valide.

```

ok i could save it under others but i do not know how to do it. i tried to validate _before_ with phonenumbers with no avails.

Tryton spits error when you save, not when you affect. how can i manage this ? Maybe there is a internal way of validation for tryton ?

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 6, 2025, 9:22pm UTC](https://discuss.tryton.org/t/phone-number-validation/8379/2 "2025-03-06T21:22:24Z")

</div>

Your party should have a country set on the addresses. Based on those countries Tryton will check if the phone number is valid.

I’ve tested it on the demo server and it just works. The phone number also got rewritten to ‘+1 819-944-2765’

---

<div class="post-metadata">

### Author: ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)
#### Post date: [March 7, 2025, 8:04am UTC](https://discuss.tryton.org/t/phone-number-validation/8379/3 "2025-03-07T08:04:06Z")

</div>

the party _has_ a country on the adress and the number is rewrite

```auto
Country = Model.get('country.country')
the_country, = Country.find([('code', '=', 'CA')])
party.addresses.append(Address(street=args.adresse,postal_code=args.cp, city=args.ville, country=the_country,invoice=True,delivery=True)) 
party.save() 
# Party should be saved with an adresse in Canada
party.contact_mechanisms.append(ContactMechanism(type='phone',value='819-944-2588'))
 
==> Le numéro de téléphone « +33 8199442588 » du tiers « tartempion » n'est pas valide. 

```

proteus-tryton tries to validate it as a _french_ (???) number. i tried

```auto
with my_config.set_context(country='CA'):

```

but it did not work.

---

<div class="post-metadata">

### Author: ![pnunez](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pnunez](https://discuss.tryton.org/u/pnunez)
#### Post date: [March 13, 2025, 3:50pm UTC](https://discuss.tryton.org/t/phone-number-validation/8379/4 "2025-03-13T15:50:29Z")

</div>

The party must be added to ContactMechanism creation in order to resolve the country from the address:

```python
party.contact_mechanisms.append(ContactMechanism(party=party, type='phone',value='819-944-2588'))

```
