[SalesForce] Phone Field in Custom Object

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!

Best Answer

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

Related Topic