Format, store, display US phone number

Seems like this should be super easy, but I just can’t seem to get it right.

How do I:

  1. Accept a US phone number from an input that looks like XXX-XXX-XXXX.
  2. Store it in the database.
  3. Display it on a page in the correct format (XXX-XXX-XXXX).

Notes:
I have the input’s content format set to US Phone:

But when I try to save the number to the database, it won’t let me just format the number as a phone:
Screenshot 2020-06-13 14.11.10

I have the field set to type = number:

1 Like

Hey there :wave:

Let me take a stab at it for you. Two ideas:

  1. You still save it as a number in your database. Just when you display it on the screen you can choose the number, then click on more. Choose formatted as. Then you can choose phone number formatting.

  2. If you really want to save it like that in your database then you can save it as text.

So those are two options for you.

Want to learn more?

www.nocodeminute.com

Presenting

Hope that helps! :blush:

2 Likes

Okay, thank you, that does seem to work. I guess what was tripping me up is that it doesn’t seem to let me directly format the display text as a phone number.

First it seems I have to format it as a number, then format THAT number as phone number. I would have thought that making the [content format = US Phone] on the input would have eliminated the need to format the number twice on the text display. Not a huge deal, but it seems odd to me, unless I’m missing something?

Screenshot 2020-06-13 15.19.14

2 Likes

I’m not in front of my computer at the moment but maybe you need to save it as text to get it to show the option. I just can’t remember at the moment.

I think you need to save the phone number in your database as text.

Check it out: Phone number data type not recognized as number

The reason it was working the way you have it is because when you say formatted as: it changes the number to a text type.

2 Likes

Perfect, thank you! (Not sure why that post didn’t come up when I searched for “phone number” but I clearly need to do a better job searching.)

No problem. Happy to point you in the right direction. :+1:

This topic was automatically closed after 70 days. New replies are no longer allowed.