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
MRivasMRivas 

Regex validation giving a false positive.

Hi all, I have a Regex for a phone validation and I want the phone to be entered in the following formats: XXXXXXXXXX, XXX-XXX-XXXX, (XXX) XXX-XXXX, (XXX)XXX-XXXX. Currently this validation is allowing false positives to be saved. In example (414 903-0980 or 343_989_0989 or 898)7879898. I am not sure how to fix it. Here is what I am using. 

(REGEX(Phone, "\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$"))

 

VinayVinay (Salesforce Developers) 
False postives ? is it allowing negative values as well?  Can you post screenshot of what you have?

Thanks,
CharuDuttCharuDutt

Hii MRIVAS
Try Below Validation

NOT( OR( ISBLANK(Phone), 
REGEX( Phone,"(\\D?[0-9]{3}\\D?)[\\s][0-9]{3}-[0-9]{4}")),
REGEX( Phone,"[0-9]{3}-[0-9]{3}-[0-9]{4}"))
)
Please Mark It As Best Answer If It Helps
Thank You!
MRivasMRivas
User-added image
It is allowing me to save the phone numbers like this: (xxxxxxxxx or xxx)xxxxxxx