function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
r999r999 

How can we count number of digits in a number

I want to count the number of digits in a phone number to restrict the number to 10 digits or some customized number only. I tried this with Len(text), but could not get it. Do we have any other validation already available for this? please let me know if there is any possibility to use count function for this.

Thsnks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

You can write the validation rule as below:

 

LEN(Phone) > 10.

Error message: Phone number can’t be greater than 10.

 

OR

 

IF(LEN(  text( value(Phone ) ) ) == 10, true, false)

Error message: Phone number can’t be greater than 10.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

r999r999

Thanks to this forum. I got it from the other posts that we can get it by using

 

NOT(
LEN(Phone)==10 ). But do we have any ways to avoid NOT for this?

Navatar_DbSupNavatar_DbSup

Hi,

You can write the validation rule as below:

 

LEN(Phone) > 10.

Error message: Phone number can’t be greater than 10.

 

OR

 

IF(LEN(  text( value(Phone ) ) ) == 10, true, false)

Error message: Phone number can’t be greater than 10.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
abi Kafleyabi Kafley
if 'Phone' is data type number then it is giving syntax error. i was trying to validiate SSN to be equal to 7 digit  taking this reference but couldn't do it. the formula i used is AND((ISBLANK(SSN__C), NOT(LEN( SSN__C)=7). the syntax error massage is expected text, receive number, can anyone help mention the correct way.
Pooja Gupta 54Pooja Gupta 54
@Abi I am facing the issue. I want to create a validation rule on custom object called credit card to limit the no of digits to 11. But when I am trying to follow this thread I am gettng the the syntax error message as expected text, received number. Can anyone help on this?
 
Siddhartha GantediSiddhartha Gantedi
@Pooja Gupta 54. if you haven't resolved this, try converting the data type of the credit card to text and use LEN(text) function.