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
aaryan sriaaryan sri 

phone validation

HI,

  Am trying to restrict phone no to 10 digits and i should accept format either (999) 999-9999 or 999-999-9999 or 999999999.
I wrote below validation 
AND(
    NOT(ISBLANK(Prescriber_Phone_Number_Last_Fill_Date__c)),
    NOT(
        OR(
            ISNUMBER(Prescriber_Phone_Number_Last_Fill_Date__c ),
            REGEX(Prescriber_Phone_Number_Last_Fill_Date__c,"[0-9]{3}-[0-9]{3}-[0-9]{4}"),
            REGEX(Prescriber_Phone_Number_Last_Fill_Date__c, "\\D*?(\\d\\D*?){10}"),
            REGEX(Prescriber_Phone_Number_Last_Fill_Date__c, "[0-9]{10}")
        )
    )
)    

It is allowing more than 10 and Alphabets .

 Can somebody help me how to fix this?
 
ajay Duggi(Heptarc)ajay Duggi(Heptarc)
Dear aaryan,

Try this once
AND( NOT(ISBLANK(Phone)), LEN(Phone) < 10 )
Raj VakatiRaj Vakati
Try this one will work for all cases 

 
AND(
    NOT(ISBLANK(Prescriber_Phone_Number_Last_Fill_Date__c)),
    NOT(
        OR(
            ISNUMBER(Prescriber_Phone_Number_Last_Fill_Date__c ),
            REGEX(Prescriber_Phone_Number_Last_Fill_Date__c,"^(([\+]{1}[0-9]{1,3}[\ ]{1}[0-9]{1,2}[\ ]{1}[0-9]{4}[\ ]{1}[0-9]{4})|([0]{1}[0-9]{1}[\ ]{1}[0-9]{4}[\ ]{1}[0-9]{4})|([0]{1}[0-9]{1}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4})|([\(]{1}[0]{1}[0-9]{1}[\)]{1}[\ ]{1}[0-9]{4}([\ ]|[\-]){1}[0-9]{4})|([0-9]{4}([\ ]|[\-])?[0-9]{4})|([0]{1}[0-9]{3}[\ ]{1}[0-9]{3}[\ ]{1}[0-9]{3})|([0]{1}[0-9]{9})|([\(]{1}[0-9]{3}[\)]{1}[\ ]{1}[0-9]{3}[\-]{1}[0-9]{4})|([0-9]{3}([\/]|[\-]){1}[0-9]{3}[\-]{1}[0-9]{4})|([1]{1}[\-]?[0-9]{3}([\/]|[\-]){1}[0-9]{3}[\-]{1}[0-9]{4})|([1]{1}[0-9]{9}[0-9]?)|([0-9]{3}[\.]{1}[0-9]{3}[\.]{1}[0-9]{4})|([\(]{1}[0-9]{3}[\)]{1}[0-9]{3}([\.]|[\-]){1}[0-9]{4}(([\ ]?(x|ext|extension)?)([\ ]?[0-9]{3,4}))?)|([1]{1}[\(]{1}[0-9]{3}[\)]{1}[0-9]{3}([\-]){1}[0-9]{4})|([\+]{1}[1]{1}[\ ]{1}[0-9]{3}[\.]{1}[0-9]{3}[\-]{1}[0-9]{4})|([\+]{1}[1]{1}[\ ]?[\(]{1}[0-9]{3}[\)]{1}[0-9]{3}[\-]{1}[0-9]{4}))$")
        )
    )
)

 
Neeraj Singh 55Neeraj Singh 55
Hi Aaryan,


Try this once

OR(NOT(REGEX(  Phone , "\\D*?(\\d\\D*?){10}")), NOT(ISNUMBER(  Phone )))

It contains only ten digits not more than or not less than.

Thanks 
Neeraj
 
aaryan sriaaryan sri
Thanks every one who responded to my Question.

I fixed my issue with below changes and it start working what am looking the formates.
AND( 
If( 
ISBLANK(Prescriber_Phone_Number_Last_Fill_Date__c),Null,
NOT( 
OR(
REGEX(Prescriber_Phone_Number_Last_Fill_Date__c,"[0-9]{3}-[0-9]{3}-[0-9]{4}"),
REGEX(Prescriber_Phone_Number_Last_Fill_Date__c,"\\([0-9]{3}\\)-[0-9]{3}-[0-9]{4}"), 
REGEX(Prescriber_Phone_Number_Last_Fill_Date__c,"[0-9]{10}") 



),