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
sumpritsumprit 

Validation Rule for International Format

Hi there,

I already have the validation rule created for Phone Validation field - 10 digits with 4 digits extension? This works great. But would also like make sure, that it also checks for International Format.

AND(LEN(Phone) <> 0,
NOT (
AND(

LEFT(Phone,1)="(",
MID(Phone,5,1)=")",
MID(Phone,6,1)=" ",
MID(Phone,10,1)="-",


CONTAINS("0123456789", MID (Phone, 2, 1)),
CONTAINS("0123456789", MID (Phone, 3, 1)),
CONTAINS("0123456789", MID (Phone, 4, 1)),
CONTAINS("0123456789", MID (Phone, 7, 1)),
CONTAINS("0123456789", MID (Phone, 8, 1)),
CONTAINS("0123456789", MID (Phone, 9, 1)),
CONTAINS("0123456789", MID (Phone, 11, 1)),
CONTAINS("0123456789", MID (Phone, 12, 1)),
CONTAINS("0123456789", MID (Phone, 13, 1)),
CONTAINS("0123456789", MID (Phone, 14, 1)),

OR(AND(LEN(Phone)<=20,MID(Phone, 15,2)=" x",

CONTAINS("0123456789", MID (Phone, 17, 1)),
CONTAINS("0123456789", MID (Phone, 18, 1)),
CONTAINS("0123456789", MID (Phone, 19, 1)),
CONTAINS("0123456789", MID (Phone, 20, 1))
), LEN(Phone)<=14
)
)
)
)


What needs to be added ?

I got this from the doc:-

LEFT(Phone, 1) <> "+"

Also, if I add the above logic would it not conflict with the 10 digit rule?




Best Answer chosen by Admin (Salesforce Developers) 
EricBEricB
You can simplify this validation rule a lot using the new ISNUMBER() function instead of CONTAINS("0123456789",...

If you feel really daring, you might try using the REGEX function with a regular expression for international phone number.

I found this web site with some examples:
http://regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7

Eric

All Answers

EricBEricB
You can simplify this validation rule a lot using the new ISNUMBER() function instead of CONTAINS("0123456789",...

If you feel really daring, you might try using the REGEX function with a regular expression for international phone number.

I found this web site with some examples:
http://regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7

Eric
This was selected as the best answer
sumpritsumprit
Here is what I did recently few minutes ago:-

AND(LEN(Phone) <> 0,
NOT (
AND(
LEN(Phone)<=30,
LEFT(Phone,1)="(", MID(Phone,5,1)=")", MID(Phone,6,1)=" ", MID(Phone,10,1)="-",
NOT(ISNUMBER(Phone))
OR(AND(LEN(Phone)<=20,MID(Phone, 15,2)=" x"))
)))

Notice, I am trying to use ISNUMBER function which is easier. If you see the code above (the very first code) I am trying to convert that code from CONTAINS to be using ISNUMBER function.

In the above code I am trying to acheive the following:-

1.> No Texts are allowed in the Phone field
2.> Auto-Formatting Script which is already in SF is also being intact. Eg; (765) 098-7789
3.> I also want to allow upto 7 digits of Phone extension.
4.> I also want to allow Internations Formatiing too.


Any ideas from here?
TheBootTheBoot

I need help on this too!  I am adding users in other countries for the first time, and trying to address their various phone formatting issues.  I am surprised this is not more automatic in SF.  But I am not here to complain.

It sounds like you are trying to do an awful lot in one field - not that that is bad - just very ambitious.  I was beginning to approach the problem from a standpoint of creating country specific phone fields.  I am already creating country specific page layouts, so I could change the phone fields on each layout to be the one for that country. 

I hope I am not confusing the issue here, but let me know what you think of this approach, and I also look forward to hear what else you discover in solving this problem.

Thanks!

-B

sumpritsumprit
Try this one..

NOT(REGEX( Phone,"^((\\+\\d{1,3}(-| )?\\(?\\d\\)?(-| )?\\d{1,3})|(\\(?\\d{2,3}\\)?))(-| )?(\\d{3,4})(-| )?(\\d{4})(( x)\\d{1,8}){0,1}$"))
sumpritsumprit
Hi there,
 
Can someone still assist me on this one please?
 
 
thanks