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
kiransure kumarkiransure kumar 

HOW TO VALIDATE PHONE DATATYPE FIELD WITH VALIDATION RULE

hi i want to validate a phone number field of phone datatype. now my rule is phone number must be a 10 digit number  and it should not be a blank one .....now i used formula NOT(LEN(PHONENUMBER_C)=10).NO THERE IS NO SYNTAX ERROR AND SAVED THE RULE .WHEN I ENTERING IN PHONENUMBER FILED LIKE 9966055438 IT IS A TEN DIGIT NUMBER SO MY RECORD WILL HAVE TO SAVE .BUT AN ERROR WILL COME WHILE SAVING IT AND THAT PHONENUMBER IN DAT FIELD SHOWS LIKE DIS (996) 6055-438.IT IS NOT SAVING WHY THIS HAPPENING ? CAN ANY ONE TELL ME THE REASON   
Best Answer chosen by kiransure kumar
SantoshChitalkarSantoshChitalkar
Hi Kiran,

It is not saving because
1)  you use a LEN to calculate the length
2) you use a data type as Phone which add the extension automatically

So in your case it is giving error because LEN calculate the complete input including spaces which is 
(996) 6055-438. For this input, length is 14. So if you want to use the validation and phone datatype, then there two ways to make it work -
1) Instead of 10 use 14 like NOT(LEN(PHONENUMBER_C)=14)
2) Use REGEX

Regards,
Santosh Chitalkar

All Answers

Mrunali GaonkarMrunali Gaonkar
Hi kiransure kumar,
   Data type of your phone number field is Phone hence it is getting display like (996) 6055-438. Instad of phone change the data type as number.while changing datatype to number check the checkbox for Always require a value in this field in order to save a record(Required) so that it ll never b blank. write the same validation for this field.

Thanx and Regards,
Mrunali Gaonkar
SantoshChitalkarSantoshChitalkar
Hi Kiran,

It is not saving because
1)  you use a LEN to calculate the length
2) you use a data type as Phone which add the extension automatically

So in your case it is giving error because LEN calculate the complete input including spaces which is 
(996) 6055-438. For this input, length is 14. So if you want to use the validation and phone datatype, then there two ways to make it work -
1) Instead of 10 use 14 like NOT(LEN(PHONENUMBER_C)=14)
2) Use REGEX

Regards,
Santosh Chitalkar
This was selected as the best answer