0

I'm trying to create a validation rule for Phone Numbers. Say, I have three Phone Number fields that should be checked if the values meet the following requirements:

  1. phone numbers should be 10-12 digits in length
  2. only numbers are accepted
  3. "+" symbol in the beginning of the number is still acceptable

I came up with a rule using REGEX but it only accepts numbers that start with +. Clearly not the requirement since putting + in the beginning is just optional.

This is my rule so far:

NOT( 
AND( 
OR( 
LEN(Phone) = 0, 
REGEX(Phone, "\\+[0-9 ]+") 
), 
OR( 
LEN(MobilePhone) = 0, 
REGEX(MobilePhone, "\\+[0-9 ]+") 
), 
OR( 
LEN(OtherPhone) = 0, 
REGEX(OtherPhone, "\\+[0-9 ]+") 
) 
) 
)

I'm hoping if you can spare some time to help me with my validation rule. I'm still new to Salesforce so I'm still figuring things out. Thank you.

1

There is already another answer with shorter solution but I still wanted to answer. Below validation rule should work for your situation, too.

OR( 
OR( 
LEN( Phone ) <= 9 , 
LEN( Phone ) >= 13 
), 
NOT( 
OR( 
REGEX(Phone, "[0-9 ]+"), 
REGEX(Phone, "\\+[0-9 ]+")) 
) 
)
  • Hi @Tugce Sirin. Thank you for you reply. I tried this rule but I noticed that the field still accepts letters. Can you check? – Emman May 26 '16 at 6:03
  • Hi @Emman I've edited my answer. Please try updated answer. – tugce May 26 '16 at 6:55
  • Hi @Tugce Sirin. Thank you for this! It works great! You saved me there! :D – Emman May 26 '16 at 8:53
  • Hi @tugce sirin. I hope you could help me further. The requirement has been changed. The validation rule should check that the length should only be 12 if the number starts with '00', the length should only be 11 if the number starts with +, and the length should only be 10 if it starts with any number except '00'. I'm lost on how to implement this. Thank you. – Emman May 31 '16 at 9:41
1

You can use following RegEx for making sure the phone number has 10 to 12 digits and starts with a + sign,

REGEX(<Phone Field Name>, "\\+{0,1}[0-9]{10,12}")

Hope this helps.

Best Regards!

  • hi Dnyanesh, thanks for the reply. Apologies for not making the question clear. This would work if the "+" sign is required. However, the user can input phone numbers with or without "+" sign but at the same time it should also check if the inputted value does not contain letters and/or special characters. – Emman May 26 '16 at 5:55
  • Hi @Emman, \\+{0,1} ensures that there can minimum 0 to maximum 1 instance of the character +. Also, [0-9]{10,12} ensures that there are at least 10 and maximum 12 digits. Please let me know if it doesn't work that way. – Dnyanesh KC May 26 '16 at 6:05
0
not(isnumber(your phone number field))||len(your phone number field)<>**10**)

As I'm an Indian My mobile number should be equal to 10 you can add any number over there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.