Skip to main content
davinar9817
Known Participant
Dec 16, 2022 4:19 PM UTC
Question

Format Phone Number with Hyphens

So I want to be able for the user to add hyphens into their phone number(s) when entered into a form I have.

Whenever I add hyphens to the phone number field it pushes the hyphens to the very front for some reason, like this

but I want it to stay like this

Here's my code

a!textField(
                          label: "Contractor's Phone Number",
                          labelPosition: "ABOVE",
                          value: ri!record['recordType!{d327a5dc-18d4-4ffd-8bdf-6a22b134677f}DS Contractor.fields.{f2502f28-185b-4cdb-87eb-56e09d28d249}conphoneNum'],
                          saveInto: ri!record['recordType!{d327a5dc-18d4-4ffd-8bdf-6a22b134677f}DS Contractor.fields.{f2502f28-185b-4cdb-87eb-56e09d28d249}conphoneNum'],
                          refreshAfter: "UNFOCUS",
                          required: true,
                          characterLimit: 12,
                          validations:	{}
                           
                            )

    5 replies

    stefanhelzle0001
    Brainy
    Dec 16, 2022 6:08 PM UTC

    Could it be that you defined that record field as a number? Try to change this to text.

    davinar9817
    Known Participant
    Dec 16, 2022 6:17 PM UTC

    It does seem to be an integer. However it's also my primary key, so it won't let me change or delete it. Is there a way to do either?

    stefanhelzle0001
    Brainy
    Dec 16, 2022 6:39 PM UTC

    Using a value entered by a user as a primary key seems to be a bad idea. I recommend to have a separate field "id" (integer) defined as auto generated primary key. Then store the phone number in a text field.

    prasantap0900
    Participating Frequently
    Feb 27, 2025 7:31 AM UTC


    a!textField(
      label: "Phone Number",
      value: {
        text(
          ri!number,
          "000-000-000"
        )
      },
      saveInto: ri!number
    )