6

When I add Phone field in custom Object, I want to the user to enter minimum of 10 digits, if the user enters less than 10 digits they should get error [Just the numbers, no need of any special characters inclusion like +1 (666) 777-8910 just '6667778910']. Can anyone please help me with the formula for this criteria to enter in validation rule?

Thanks in advance!

1 Answer 1

3

As @crmprogdev mentioned, I would recommend to use RegEx. See this example for US Phone number has 10 digits in (999) 999-9999 format: NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}")) in UsefulValidationRules

If you don't like RegEx, you can use an alternativly an onion-like SUBSTITUTE. If you need other characters excluded, you'll have to add more SUBSTITUTEs. TRIM removes white space and LEN counts the cleaned results:

 LEN(
   SUBSTITUTE(
     SUBSTITUTE(
       SUBSTITUTE( 
         TRIM(YourFieled__c) 
       , "+", "")
     , "(", "")
   , ")", "")
 ) < 10

See also

2
  • 1
    Actually, you can use RegEx to replace characters. See this example for US Phone number has 10 digits in (999) 999-9999 format: NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}")) in UsefulValidationRules. This could be modified to handle other situations as well.
    – crmprogdev
    Mar 7, 2015 at 15:27
  • @crmprogdev - thanks for your headsup, you are right. I updated my answer.
    – Uwe Heim
    Mar 7, 2015 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .