Creating Phone number from Two Different Questions

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the error
message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image: Inline
images 5], MainContactNumber), concat( CountryCode[image: Inline images 7]
MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw

Hi Yaw,

It looks like what you have is correct, only when you check if CountryCode
equals ‘Other’, you’ll want to just use an equal sign “=” (it looks like
you currently have “.=”).

Also note that when converting mobile numbers to international format, you
might need to alter the national number before concatenating (which you’re
representing with MainContactNumber) based on the country. For example,
national phone numbers in Ghana consist of a ‘0’ followed by 9 digits.
Before concatenating a national number in Ghana with the 233 country code,
you’d need to remove the leading ‘0’ from the national number using the
substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that users
enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

··· On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the error
message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image: Inline
images 5], MainContactNumber), concat( CountryCode[image: Inline images 7]
MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dear Giovanni,
Thank you very much. I don’t really know how the dot got there and I spent
about 2 hours verifying and still couldn’t detect it. It is working now.

In fact, on the form, I gave instructions that the MainContactNumber should
be entered without the leading zero but I would like to try your suggestion
about the use of the substr function. This will make it easier for client
to also use that phone number locally without having to add the zero.

My concern is that will the substr function work on a Phone Number
question since it is a String function? I mean the MainContacNumber is a
Phone Number Question and the substr function’s argument is supposed to
be a string.

Thank you very much for the suggestion as well as spotting the mistake in
the <if statement>.
Yaw

··· On 19 November 2016 at 13:39, Giovanni Capalbo wrote:

Hi Yaw,

It looks like what you have is correct, only when you check if CountryCode
equals ‘Other’, you’ll want to just use an equal sign “=” (it looks like
you currently have “.=”).

Also note that when converting mobile numbers to international format, you
might need to alter the national number before concatenating (which you’re
representing with MainContactNumber) based on the country. For example,
national phone numbers in Ghana consist of a ‘0’ followed by 9 digits.
Before concatenating a national number in Ghana with the 233 country code,
you’d need to remove the leading ‘0’ from the national number using the
substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that users
enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI <yawantwiadjei@gmail.com wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the error
message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image: Inline
images 5], MainContactNumber), concat( CountryCode[image: Inline images
7] MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Yaw,

Yes, the substr function will work with the “Phone Number or Numeric ID”
question type. Note that if you have your users enter the number with the
leading zero, then you’ll have to make sure that all countries you’re
working with follow that convention.

You can remove the leading zero with an expression like:

substr(#form/MainContactNumber, 1, string-length(#form/MainContactNumber))

And you can enforce that it’s entered with the leading zero by using a
Validation Condition on the MainContactNumber question like:

regex(., “^0\d+$”)

Thanks,
Giovanni

··· On Sun, Nov 20, 2016 at 7:06 AM, YAW ANTWI-ADJEI wrote:

Dear Giovanni,
Thank you very much. I don’t really know how the dot got there and I spent
about 2 hours verifying and still couldn’t detect it. It is working now.

In fact, on the form, I gave instructions that the MainContactNumber
should be entered without the leading zero but I would like to try your
suggestion about the use of the substr function. This will make it
easier for client to also use that phone number locally without having to
add the zero.

My concern is that will the substr function work on a Phone Number
question since it is a String function? I mean the MainContacNumber is a
Phone Number Question and the substr function’s argument is supposed to
be a string.

Thank you very much for the suggestion as well as spotting the mistake in
the <if statement>.
Yaw

On 19 November 2016 at 13:39, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

It looks like what you have is correct, only when you check if
CountryCode equals ‘Other’, you’ll want to just use an equal sign “=” (it
looks like you currently have “.=”).

Also note that when converting mobile numbers to international format,
you might need to alter the national number before concatenating (which
you’re representing with MainContactNumber) based on the country. For
example, national phone numbers in Ghana consist of a ‘0’ followed by 9
digits. Before concatenating a national number in Ghana with the 233
country code, you’d need to remove the leading ‘0’ from the national number
using the substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that users
enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the
error message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image: Inline
images 5], MainContactNumber), concat( CountryCode[image: Inline images
7] MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi,
Thank you very much. What does he backslah d (\d) mean?.

Yaw

··· On 22 November 2016 at 00:47, Giovanni Capalbo wrote:

Hi Yaw,

Yes, the substr function will work with the “Phone Number or Numeric ID”
question type. Note that if you have your users enter the number with the
leading zero, then you’ll have to make sure that all countries you’re
working with follow that convention.

You can remove the leading zero with an expression like:

substr(#form/MainContactNumber, 1, string-length(#form/MainContactNumber))

And you can enforce that it’s entered with the leading zero by using a
Validation Condition on the MainContactNumber question like:

regex(., “^0\d+$”)

Thanks,
Giovanni

On Sun, Nov 20, 2016 at 7:06 AM, YAW ANTWI-ADJEI yawantwiadjei@gmail.com wrote:

Dear Giovanni,
Thank you very much. I don’t really know how the dot got there and I
spent about 2 hours verifying and still couldn’t detect it. It is working
now.

In fact, on the form, I gave instructions that the MainContactNumber
should be entered without the leading zero but I would like to try your
suggestion about the use of the substr function. This will make it
easier for client to also use that phone number locally without having to
add the zero.

My concern is that will the substr function work on a Phone Number
question since it is a String function? I mean the MainContacNumber is a
Phone Number Question and the substr function’s argument is supposed
to be a string.

Thank you very much for the suggestion as well as spotting the mistake in
the <if statement>.
Yaw

On 19 November 2016 at 13:39, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

It looks like what you have is correct, only when you check if
CountryCode equals ‘Other’, you’ll want to just use an equal sign “=” (it
looks like you currently have “.=”).

Also note that when converting mobile numbers to international format,
you might need to alter the national number before concatenating (which
you’re representing with MainContactNumber) based on the country. For
example, national phone numbers in Ghana consist of a ‘0’ followed by 9
digits. Before concatenating a national number in Ghana with the 233
country code, you’d need to remove the leading ‘0’ from the national number
using the substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that users
enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the
error message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image:
Inline images 5], MainContactNumber), concat( CountryCode[image:
Inline images 7] MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Yaw,

The \d in a regular expression matches any numerical digit 0-9. So the
regular expression “^0\d+$” matches strings that only consist of all digits
and start with a 0.

Thanks,
Giovanni

··· On Tue, Nov 22, 2016 at 4:45 AM, YAW ANTWI-ADJEI wrote:

Hi,
Thank you very much. What does he backslah d (\d) mean?.

Yaw

On 22 November 2016 at 00:47, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

Yes, the substr function will work with the “Phone Number or Numeric ID”
question type. Note that if you have your users enter the number with the
leading zero, then you’ll have to make sure that all countries you’re
working with follow that convention.

You can remove the leading zero with an expression like:

substr(#form/MainContactNumber, 1, string-length(#form/MainContac
tNumber))

And you can enforce that it’s entered with the leading zero by using a
Validation Condition on the MainContactNumber question like:

regex(., “^0\d+$”)

Thanks,
Giovanni

On Sun, Nov 20, 2016 at 7:06 AM, YAW ANTWI-ADJEI <yawantwiadjei@gmail.com wrote:

Dear Giovanni,
Thank you very much. I don’t really know how the dot got there and I
spent about 2 hours verifying and still couldn’t detect it. It is working
now.

In fact, on the form, I gave instructions that the MainContactNumber
should be entered without the leading zero but I would like to try your
suggestion about the use of the substr function. This will make it
easier for client to also use that phone number locally without having to
add the zero.

My concern is that will the substr function work on a Phone Number
question since it is a String function? I mean the MainContacNumber is a
Phone Number Question and the substr function’s argument is supposed
to be a string.

Thank you very much for the suggestion as well as spotting the mistake
in the <if statement>.
Yaw

On 19 November 2016 at 13:39, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

It looks like what you have is correct, only when you check if
CountryCode equals ‘Other’, you’ll want to just use an equal sign “=” (it
looks like you currently have “.=”).

Also note that when converting mobile numbers to international format,
you might need to alter the national number before concatenating (which
you’re representing with MainContactNumber) based on the country. For
example, national phone numbers in Ghana consist of a ‘0’ followed by 9
digits. Before concatenating a national number in Ghana with the 233
country code, you’d need to remove the leading ‘0’ from the national number
using the substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that
users enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the
error message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image:
Inline images 5], MainContactNumber), concat( CountryCode[image:
Inline images 7] MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Giovanni,
Thank you for the explanation.

My country code (CountryCode) is a Multi-Choice question where the
frontline worker selects the actual country name but it is the code such as
233 or 234 that will be concatenated with the MainContactNumber which is a
Phone Number question. Will this be recognised by the Messaging system as a
proper phone number to send text message to?

Yaw

··· On 22 Nov 2016 12:29 p.m., "Giovanni Capalbo" wrote:

Hi Yaw,

The \d in a regular expression matches any numerical digit 0-9. So the
regular expression “^0\d+$” matches strings that only consist of all
digits and start with a 0.

Thanks,
Giovanni

On Tue, Nov 22, 2016 at 4:45 AM, YAW ANTWI-ADJEI yawantwiadjei@gmail.com wrote:

Hi,
Thank you very much. What does he backslah d (\d) mean?.

Yaw

On 22 November 2016 at 00:47, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

Yes, the substr function will work with the “Phone Number or Numeric ID”
question type. Note that if you have your users enter the number with the
leading zero, then you’ll have to make sure that all countries you’re
working with follow that convention.

You can remove the leading zero with an expression like:

substr(#form/MainContactNumber, 1, string-length(#form/MainContac
tNumber))

And you can enforce that it’s entered with the leading zero by using a
Validation Condition on the MainContactNumber question like:

regex(., “^0\d+$”)

Thanks,
Giovanni

On Sun, Nov 20, 2016 at 7:06 AM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Dear Giovanni,
Thank you very much. I don’t really know how the dot got there and I
spent about 2 hours verifying and still couldn’t detect it. It is working
now.

In fact, on the form, I gave instructions that the MainContactNumber
should be entered without the leading zero but I would like to try your
suggestion about the use of the substr function. This will make it
easier for client to also use that phone number locally without having to
add the zero.

My concern is that will the substr function work on a Phone Number
question since it is a String function? I mean the MainContacNumber is a
Phone Number Question and the substr function’s argument is supposed
to be a string.

Thank you very much for the suggestion as well as spotting the mistake
in the <if statement>.
Yaw

On 19 November 2016 at 13:39, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

It looks like what you have is correct, only when you check if
CountryCode equals ‘Other’, you’ll want to just use an equal sign “=” (it
looks like you currently have “.=”).

Also note that when converting mobile numbers to international format,
you might need to alter the national number before concatenating (which
you’re representing with MainContactNumber) based on the country. For
example, national phone numbers in Ghana consist of a ‘0’ followed by 9
digits. Before concatenating a national number in Ghana with the 233
country code, you’d need to remove the leading ‘0’ from the national number
using the substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that
users enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the
error message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image:
Inline images 5], MainContactNumber), concat( CountryCode[image:
Inline images 7] MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Yaw,

Yes, that should be fine. You can test it out and look at the
contact_phone_number case property that your workflow creates, and as long
as it’s a string of digits and it shows up as you expect it to, then
CommCare messaging will be able to send to that number.

Thanks,
Giovanni

··· On Tue, Nov 22, 2016 at 7:44 AM, YAW ANTWI-ADJEI wrote:

Hi Giovanni,
Thank you for the explanation.

My country code (CountryCode) is a Multi-Choice question where the
frontline worker selects the actual country name but it is the code such as
233 or 234 that will be concatenated with the MainContactNumber which is a
Phone Number question. Will this be recognised by the Messaging system as a
proper phone number to send text message to?

Yaw

On 22 Nov 2016 12:29 p.m., “Giovanni Capalbo” gcapalbo@dimagi.com wrote:

Hi Yaw,

The \d in a regular expression matches any numerical digit 0-9. So the
regular expression “^0\d+$” matches strings that only consist of all
digits and start with a 0.

Thanks,
Giovanni

On Tue, Nov 22, 2016 at 4:45 AM, YAW ANTWI-ADJEI <yawantwiadjei@gmail.com wrote:

Hi,
Thank you very much. What does he backslah d (\d) mean?.

Yaw

On 22 November 2016 at 00:47, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

Yes, the substr function will work with the “Phone Number or Numeric
ID” question type. Note that if you have your users enter the number with
the leading zero, then you’ll have to make sure that all countries you’re
working with follow that convention.

You can remove the leading zero with an expression like:

substr(#form/MainContactNumber, 1, string-length(#form/MainContac
tNumber))

And you can enforce that it’s entered with the leading zero by using a
Validation Condition on the MainContactNumber question like:

regex(., “^0\d+$”)

Thanks,
Giovanni

On Sun, Nov 20, 2016 at 7:06 AM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Dear Giovanni,
Thank you very much. I don’t really know how the dot got there and I
spent about 2 hours verifying and still couldn’t detect it. It is working
now.

In fact, on the form, I gave instructions that the MainContactNumber
should be entered without the leading zero but I would like to try your
suggestion about the use of the substr function. This will make it
easier for client to also use that phone number locally without having to
add the zero.

My concern is that will the substr function work on a Phone Number
question since it is a String function? I mean the MainContacNumber is a
Phone Number Question and the substr function’s argument is
supposed to be a string.

Thank you very much for the suggestion as well as spotting the mistake
in the <if statement>.
Yaw

On 19 November 2016 at 13:39, Giovanni Capalbo gcapalbo@dimagi.com wrote:

Hi Yaw,

It looks like what you have is correct, only when you check if
CountryCode equals ‘Other’, you’ll want to just use an equal sign “=” (it
looks like you currently have “.=”).

Also note that when converting mobile numbers to international
format, you might need to alter the national number before concatenating
(which you’re representing with MainContactNumber) based on the country.
For example, national phone numbers in Ghana consist of a ‘0’ followed by 9
digits. Before concatenating a national number in Ghana with the 233
country code, you’d need to remove the leading ‘0’ from the national number
using the substr
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
function.

Alternatively, a simpler way would be to request in your form that
users enter the MainContactNumber without the leading zero and enforce that
through validation on the MainContactNumber question.

Thanks,
Giovanni

On Fri, Nov 18, 2016 at 11:44 PM, YAW ANTWI-ADJEI < yawantwiadjei@gmail.com> wrote:

Hello,
Does anyone know how I can combine 2 questions (i.e. CountryCode and
MobileNumber) to form the ContactPhoneNumber question which will be used in
a Messaging App?

The ContactPhoneNumber is a Hidden Value Question.

I tried with the concat function with an IF statement a and got the
error message below:

Edit Calculate Condition (Advanced)Show Simple Mode
XPath Expression

if( CountryCode
[image: Inline images 6]=‘Other’,concat( OtherCountryCode[image:
Inline images 5], MainContactNumber), concat( CountryCode[image:
Inline images 7] MainContactNumber[image: Inline images 8]))

You can drag a question into the box.

Guide to Common Logic and Calculations
https://help.commcarehq.org/display/commcarepublic/Common+Logic+and+Calculations
Validation Failed

Please fix the error before leaving this page:

  Lexical error on line 1. Unrecognized text.

#invalid/xpath if(`#form/CountryCod
---------------^

Yaw


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.