Skip to main content
Question

How to limit a field ""Phone Number"" to only contain 10 digits?

  • December 14, 2017
  • 0 replies
  • 335 views

I have a field "Phone Number", I need the user to enter 10 digit phone number in the field. If the user enters digits less than or more than 10, it should display an error message. Is this possible using native functionality or needs some custom coding? I tried using Phone filed data type but it accepts any number of digits in the field. Any suggestions? 

Forum|alt.badge.img+17
  • Community Moderator
  • December 14, 2017
Hi Raj,

In the past when I have users that have run into this issue, for native functionality, I have typically made use of a formula field and a form rule to accomplish this for data entry on a form. For that to work I set up a field (In this example lets call it Phone Number Check) as a formula checkbox field. For the Phone Number Check field I used a formula of:

If(Length([Phone Number])=10, True, False)

What this means is this checkbox field only checks when the phone number is specifically 10 digits long. Then you can set up a form rule which checks to see if that Phone Number Check field is checked and if it is not checked then you can set it to Abort the Save and give them a warning message that they must use a phone number that is a valid length of 10 digits.

  • Registered
  • December 14, 2017
Also, you may want to use a more elaborate check-box formula to handle entries containing non-digit characters and extraneous spaces. Something like the following, which handles up to five instances of a period, dash, parenthesis, or space entered as a separator between digits:

var text p=ToText(Trim([Phone Number]));
var text partOne=Part($p,1,".-)( ");
var text partTwo=Part($p,2,".-)( ");
var text partThree=Part($p,3,".-)( ");
var text partFour=Part($p,4,".-)( ");
var text partFive=Part($p,5,".-)( ");

Length($partOne & $partTwo & $partThree & $partFour & $partFive) = 10

  • Author
  • Registered
  • December 15, 2017
Thank you Alex, this helped.