# Constraint for capturing telephone number in international notation

**URL:** <https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328>\
**Category:** Support\
**Created:** [June 19, 2014, 6:14pm UTC](https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328 "2014-06-19T18:14:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bashir\_Jahed](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@Bashir\_Jahed](https://forum.getodk.org/u/Bashir_Jahed)\
**Post date:** [June 19, 2014, 6:14pm UTC](https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328/1 "2014-06-19T18:14:43Z")

</div>

Dear All

Need some help with a constraint to force surveyor to enter a telephone  
number in the following format with no spaces.

+27xxxxxxxxx e.g. +27116784567

Thanks

Bash

> **···**
>
> --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [June 19, 2014, 7:04pm UTC](https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328/2 "2014-06-19T19:04:26Z")

</div>

This would be a string field ( telephone numbers cannot fit in an int ).  
Use an appearance="numbers"

> **[Question Types](https://docs.getodk.org/form-question-types/)**
>
> ODK Collect supports forms with a wide variety of question types. The exact functionality and display style of each question are specified in your XLSForm definition using the type and appearance c...

to force the numeric keyboard.

constraint = " string-length(.) = 12 and regex(.,'^+27[0-9]+$') "

you might also be able to just do:

constraint = "regex(.,'^+27[0-9]{9}$')"

See [http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html](http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)  
for the details.

> **···**
>
> On Thu, Jun 19, 2014 at 11:14 AM, Bashir Jahed wrote:
> 
> > Dear All
> > 
> > Need some help with a constraint to force surveyor to enter a telephone  
> > number in the following format with no spaces.
> > 
> > +27xxxxxxxxx e.g. +27116784567
> > 
> > Thanks
> > 
> > Bash
> > 
> > * * *
> > 
> > ```
> > <http://www.avast.com/>
> > 
> > ```
> > 
> > This email is free from viruses and malware because avast! Antivirus  
> > [http://www.avast.com/](http://www.avast.com/) protection is active.
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)

---

<div class="post-metadata">

**Author:** ![Bashir\_Jahed](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@Bashir\_Jahed](https://forum.getodk.org/u/Bashir_Jahed)\
**Post date:** [June 20, 2014, 11:16am UTC](https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328/3 "2014-06-20T11:16:42Z")

</div>

Hi

I have tried both formats with no success. I have also tried the following with no success, my regex is very bad L

constraint = "regex(^(?:(?:(|)0|+27|27)(?:1[12345678]|2[123478]|3[1234569]|4[\d]|5[134678])(?🙂 | |-|)\d{3}(?: |-|)\d{4}$)"

Dear All

Need some help with a constraint to force surveyor to enter a telephone number in the following format with no spaces.

+27xxxxxxxxx e.g. +27116784567 tel:%2B27116784567

Thanks

Bash

> **···**
>
> \_\_\_\_\_
> 
> [http://www.avast.com/](http://www.avast.com/)
> 
> This email is free from viruses and malware because avast! Antivirus [http://www.avast.com/](http://www.avast.com/) protection is active.
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com) [mailto:opendatakit%2Bunsubscribe@googlegroups.com](mailto:opendatakit%2Bunsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> * * *
> 
> This email is free from viruses and malware because avast! Antivirus protection is active.
> 
> > **[Avast | Download Free Antivirus & VPN | 100% Free & Easy](https://www.avast.com/en-us/index)**
> >
> > Join hundreds of millions of others & get free antivirus for PC, Mac, & Android. Surf safely with our VPN. Download Avast!

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [June 20, 2014, 12:31pm UTC](https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328/4 "2014-06-20T12:31:23Z")

</div>

Bashir,

Mitch's regex works great for me.

The XML should look like:

This passes:  
+27123456789

This doesn't:  
+2712345678

You can confirm with [http://rubular.com](http://rubular.com).

Yaw

> **···**
>
> -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.
> 
> On Fri, Jun 20, 2014 at 4:16 AM, Bashir Jahed [admin@osilab.net](mailto:admin@osilab.net) wrote:
> 
> > Hi
> > 
> > I have tried both formats with no success. I have also tried the following  
> > with no success, my regex is very bad L
> > 
> > constraint =  
> > "regex(^(?:(?:(|)0|+27|27)(?:1[12345678]|2[123478]|3[1234569]|4[\d]|5[134678])(?🙂  
> > | |-|)\d{3}(?: |-|)\d{4}$)"
> > 
> > Dear All
> > 
> > Need some help with a constraint to force surveyor to enter a telephone  
> > number in the following format with no spaces.
> > 
> > +27xxxxxxxxx e.g. +27116784567
> > 
> > Thanks
> > 
> > Bash
> > 
> > * * *
> > 
> > [http://www.avast.com/](http://www.avast.com/)
> > 
> > This email is free from viruses and malware because avast! Antivirus  
> > [http://www.avast.com/](http://www.avast.com/) protection is active.
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > Mitch Sundt  
> > Software Engineer  
> > University of Washington  
> > [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups](http://groups)..google.com/group/opendatakit?hl=en  
> > [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > * * *
> > 
> > [http://www.avast.com/](http://www.avast.com/)
> > 
> > This email is free from viruses and malware because avast! Antivirus  
> > [http://www.avast.com/](http://www.avast.com/) protection is active.
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Bashir\_Jahed](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@Bashir\_Jahed](https://forum.getodk.org/u/Bashir_Jahed)\
**Post date:** [June 21, 2014, 4:13pm UTC](https://forum.getodk.org/t/constraint-for-capturing-telephone-number-in-international-notation/3328/5 "2014-06-21T16:13:01Z")

</div>

Thanks All

Got it to work, strange error with the actual spreadsheet I was using, I created a new form and it works, so will just transplant the info from broken excel file to new one.

Bash

> **···**
>
> From: opendatakit@googlegroups.com [mailto:opendatakit@googlegroups.com] On Behalf Of Yaw Anokwa Sent: 20 June 2014 02:31 PM To: ODK Community Subject: Re: [ODK Community] Constraint for capturing telephone number in international notation
> 
> Bashir,
> 
> Mitch's regex works great for me.
> 
> The XML should look like:
> 
> This passes:
> 
> +27123456789
> 
> This doesn't:
> 
> +2712345678
> 
> You can confirm with [http://rubular.com](http://rubular.com).
> 
> Yaw
> 
> --
> 
> Need ODK services? [http://nafundi.com](http://nafundi.com) provides form design, server setup, professional support, and software development for ODK.
> 
> On Fri, Jun 20, 2014 at 4:16 AM, Bashir Jahed [admin@osilab.net](mailto:admin@osilab.net) wrote:
> 
> Hi
> 
> I have tried both formats with no success. I have also tried the following with no success, my regex is very bad L
> 
> constraint = "regex(^(?:(?:(|)0|+27|27)(?:1[12345678]|2[123478]|3[1234569]|4[\d]|5[134678])(?🙂 | |-|)\d{3}(?: |-|)\d{4}$)"
> 
> Dear All
> 
> Need some help with a constraint to force surveyor to enter a telephone number in the following format with no spaces.
> 
> +27xxxxxxxxx e.g. +27116784567 tel:%2B27116784567
> 
> Thanks
> 
> Bash
> 
> * * *
> 
> [http://www.avast.com/](http://www.avast.com/)
> 
> This email is free from viruses and malware because avast! Antivirus [http://www.avast.com/](http://www.avast.com/) protection is active.
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com) [mailto:opendatakit%2Bunsubscribe@googlegroups.com](mailto:opendatakit%2Bunsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)
> 
> Options: [http://groups](http://groups)..google.com/group/opendatakit?hl=en [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> * * *
> 
> [http://www.avast.com/](http://www.avast.com/)
> 
> This email is free from viruses and malware because avast! Antivirus [http://www.avast.com/](http://www.avast.com/) protection is active.
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com) [mailto:opendatakit%2Bunsubscribe@googlegroups.com](mailto:opendatakit%2Bunsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> * * *
> 
> This email is free from viruses and malware because avast! Antivirus protection is active.
> 
> > **[Avast | Download Free Antivirus & VPN | 100% Free & Easy](https://www.avast.com/en-us/index)**
> >
> > Join hundreds of millions of others & get free antivirus for PC, Mac, & Android. Surf safely with our VPN. Download Avast!
