I’m guessing you’re using input fields? Everything written into an input field will be text by default, so when saving it to the data variable you’ll have to use
NUMBER(..) for the input value. However, if you want to use the “-” format in the phone number, you might have to change the
number property to text. To make sure it’s a number, can you use set the Keyboard type of the input field to phone-pad, so the user only has access to numbers when writing. Here’s more about input validation if these examples could help.
Hmm to force the format, it’s a bit tricky. Here’s some options I tried:
I bound a page variable number to the input field value and added a Receive event node to the logic canvas and set it to page variable number has changed. After that I set the following flow and formula:
So the formula being:
IF(LENGTH(pageVars.number) == 3, RIGHT_PAD(pageVars.number, 4, "-"), IF(LENGTH(pageVars.number) == 7, RIGHT_PAD(pageVars.number, 8, "-"), pageVars.number))
This works fine and automatically appends a “-” when needed, the only issue is if the user mistypes and tries to erase the number, it won’t allow you to erase past the “-”.
Another option could be to use the primitive input component, and add the “-” when the user stops typing and focuses out of the input field, there we can use the Component OnBlur event:
The formula in the set page variable is the following:
JOIN(INSERT_ITEM_AT(SPLIT(pageVars.number, ""), 4, "-"), "")
And you can add another Set page variable node after the first one to insert the second “-”.