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
panderla kinnerapanderla kinnera 

phone number validation rule code

sandeep@Salesforcesandeep@Salesforce
Here is the code you are looking for. 
function checkPhonefield(inputPhoneNumber)
                {
                	var PhoneMatcher = /^[0-9-+]+$/;
                	if (!PhoneMatcher.test(inputPhoneNumber))
    				{
    					alert('Please provide valid Phone number');
    						return false;
    				}
    				else 
    					return true;
    				
                }

Please mark it best answer it works so that it will be helpful for others

Thanks
Sandeep Singhal
http://www.codespokes.com/ 
Dhanya NDhanya N
Hi Panderla,

Copy this formula into your Error Condition formula of validation rule.
NOT(REGEX( Phone , "\\D*?(\\d\\D*?){10}"))
Let me know if it helps you.

Thanks,
Dhanya
 
DeepthiDeepthi (Salesforce Developers) 
Hi Panderla,

Please check the below validation rule for mobile number in "+91-xxx-xxx-xxxx" and starting with "7 or 8 or 9" digits.
 
NOT(
AND( (LEN(Mobile__c)==16 ),(REGEX(Mobile__c,'[+91]{3}-[7-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}')))
)

Hope this helps you!
Best Regards,
Deepthi
Igor PetrovychIgor Petrovych
If you need a more advanced validation of a number, to make sure you really have a valid number - you can do that in the trigger handler, and use a ported libphonenumber (https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000G12oJUAR) library.