1

how to write validation rules for phone number in below format

+()-

Example : +(91)-1234567890

When end user entering value for phone number it should only allow mentioned special characters + () - and numeric numbers.

exiting validation rule

IF( ISBLANK(End_User_Contact_Phone__c) , false, NOT(REGEX(End_User_Contact_Phone__c, "\D*?(\d\D*?){10}")))

1
  • I modified like this. is it right ? IF( ISBLANK(End_User_Contact_Phone__c) , false, NOT(REGEX(End_User_Contact_Phone__c,"^(\\+)[\(\)-][0-9]")))
    – user10584
    Commented Jul 28, 2014 at 10:09

1 Answer 1

1

This should do the trick given the requirements:

NOT(REGEX(Phone, "[0-9+\\-\\(\\)]*"))

But it will allow for some funky phone numbers that are definitely not valid, e.g. "+123-+()()()"

3
  • If this is the answer that worked you should mark it as accepted (tick next to it). This isn't me angling for points, but it helps identify the solution to those searching later on, and it also helps our site stats!
    – Matt Lacey
    Commented Jul 31, 2014 at 5:10
  • NOT(REGEX(Phone_Number__c, "[0-9+\\-\(\)]*")) using validation rules.It's auto formating in US format but when record save in application.It's throwing message. Just I want to need to add space in validation rule. How can I add.
    – user10584
    Commented Aug 1, 2014 at 4:55
  • 1
    As per @LaceySnr's answer, just following the regex, escape the whitespace character \s. So your new regex will look like : NOT(REGEX(Phone, "[0-9+\\-\\(\\)\\s]*")) Commented Aug 1, 2014 at 5:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .