Format telephone numbers

Stimulsoft Reports.WEB discussion
Post Reply
ecpmiranda
Posts: 52
Joined: Sun Jun 05, 2016 9:35 pm

Format telephone numbers

Post by ecpmiranda »

I have a TextBox and need to format.
The telephone number is a string like this "27999999999" and I need to format like this "(27) 99999-9999"
How can I format this TextBox?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Format telephone numbers

Post by HighAley »

Hello.

Please, set the Custom Format with next mask:

Code: Select all

(##) #####-####
or you could use next expression:

Code: Select all

{27999999999.ToString("(##) #####-####")}
Thank you.
ecpmiranda
Posts: 52
Joined: Sun Jun 05, 2016 9:35 pm

Re: Format telephone numbers

Post by ecpmiranda »

I tried the first approach, did not work.
The field is string type and value is 99999999999 (eleven digits) two for long distance number and the rest telephone number.
ecpmiranda
Posts: 52
Joined: Sun Jun 05, 2016 9:35 pm

Re: Format telephone numbers

Post by ecpmiranda »

Try changing textformat of telephone fields on the attached report (TELEFONES DE CONTATO)
Attachments
dadosXML.xml
(5.89 KiB) Downloaded 227 times
rptFichaMatricula2.mrt
(155.48 KiB) Downloaded 228 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format telephone numbers

Post by Alex K. »

Hello,

Please try to use the following expression:

Code: Select all

{String.Format("{0:(##) #####-####}", System.Convert.ToInt64(DataSet1.TelefoneResidencialAluno))}
Thank you.
Attachments
Capture.PNG
Capture.PNG (155.61 KiB) Viewed 3845 times
ecpmiranda
Posts: 52
Joined: Sun Jun 05, 2016 9:35 pm

Re: Format telephone numbers

Post by ecpmiranda »

Is the only solution? I will have to check for null values, because not always I have a telephone number at this field.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format telephone numbers

Post by Alex K. »

Hello,

You can add the additional checks on the null values:

Code: Select all

{(DataSet1.TelefoneResidencialAluno == "" ? "" :String.Format("{0:(##) #####-####}", System.Convert.ToInt64(DataSet1.TelefoneResidencialAluno)))}
Thank you.
ecpmiranda
Posts: 52
Joined: Sun Jun 05, 2016 9:35 pm

Re: Format telephone numbers

Post by ecpmiranda »

Thanks! Problem solved!
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Re: Format telephone numbers

Post by Andrew »

Great!

We are glad to help you!
Post Reply