+ Start a Discussion
Sébastien CHAMARANDESébastien CHAMARANDE 

😩 I can't seem to get REGEX validation rule to work 😩

Hello everyone,
I might be doing something stupid...
I want the Phone field to be this format: 00 00 00 00 00, so I have set up the following validation rule: 
NOT(OR(REGEX(Phone, "[0-9]{2,2}?\\s?[0-9]{2,2}?\\s?[0-9]{2,2}?\\s?[0-9]{2,2}?\\s?[0-9]{2,2}"),ISBLANK(Phone)))
But then, it throws an error even when the format is correct.
What am I doing wrong and not seeing it?

Thanks for your help!!!
 
Best Answer chosen by Sébastien CHAMARANDE
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you try the validation as below.


OR(ISBLANK(Phone), REGEX(Phone, "^\\d{2} \\d{2} \\d{2} \\d{2} \\d{2}$"))

This only allows to save phone as xx xx xx xx xx .

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you try the validation as below.


OR(ISBLANK(Phone), REGEX(Phone, "^\\d{2} \\d{2} \\d{2} \\d{2} \\d{2}$"))

This only allows to save phone as xx xx xx xx xx .

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Sébastien CHAMARANDESébastien CHAMARANDE
Hi and thank you so much! Works like a charm and you taught me something along the way 🙏🏼