Limiting the characters for a Phone Number

2635
4
04-05-2019 06:33 AM
HannahSturm
New Contributor III

I have two fields for phone numbers in my survey.  When I add constraints into the xls form, the survey in Connect follows those constraints, but when I publish the survey and open it up in a web browser, those constraints seem to no longer apply.  I initially had the field as a double, I changed the precision and scale in the feature class, and I also tried changing the data type to text. 

I have tried the following constraints: regex(.,'[2-9]\d{2}-\d{3}-\d{4}'), regex(.,'^\d{10}$') with input Mask (D99) 999-9999

Tags (1)
0 Kudos
4 Replies
MikailaBell
New Contributor III

Use the masking column. Enter the following text.

(XXX) XXX-XXXX

0 Kudos
NickDierks1
Occasional Contributor II

Input masks do not currently work in the web form. Regular expressions should work fine, though. I just tested your first regex example, and I got it to work in the web form when used as the constraint on a text field (consider altering the expression to regex(.,'^[2-9]\d{2}-\d{3}-\d{4}$') to make sure only a matching phone number will be accepted).

If this doesn't work for your survey, would you be able to share your survey or provide more details on how it's not working?

HannahSturm
New Contributor III

I tried adding the regex to the constraint but when I publish the field still allows input for more than 10 digits. Is there anyway to get the form to stop after the 10 digits? I have attached the form.

0 Kudos
NickDierks1
Occasional Contributor II

Web forms don't seem to treat field lengths the same way the field app does. The field will turn red, indicating an invalid input, but it's the user's responsibility to trim back the text entered. The survey still can't be submitted with extra characters in that question.

I did notice a related issue with field length: If your survey was originally published with a longer field length (255 by default if none set), then republishing with a shorter field length in that same question won't change what you can submit. You can still submit up to 255 (or whatever the original length was).

The regex formula will still help with that, as it will only accept a phone number in the format of XXX-XXX-XXXX, no more, no less. But again, nothing is going to physically stop the user from entering an invalid format or length until they try to submit.

That said, your form does need a couple changes if you're going to use that regex formula. The required field length is 12 characters, not 10 (the dashes are counted), and the input mask--while not currently honored in the web form--will interfere with validating the regex formula as written if using the field app (XXX-XXX-XXXX vs (XXX) XXX-XXXX).

0 Kudos