Applies to: Lightning and Classic |
Accuracy is a necessity when it comes to business databases. Ensuring accuracy starts with effective data entry standards.
REGEX() is a function you can use in Validation Rules to enforce specific data entry formats are followed. Through REGEX, you can set standards that ensure data is entered correctly.
Download a REGEX Rule Cheat Sheet
Below are some example functions to help you learn the cryptic format. You can use these REGEX examples or create your own to incorporate into your Salesforce Validation Rules.
[0-9]{3} or \\d{3} | Requires the numbers zero through nine to be entered 3 times |
– | Requires a dash to be entered |
[0-9]{2} or \\d{2} | Requires the numbers zero through nine to be entered 2 times |
– | Requires a dash to be entered |
[0-9]{4} or \\d{4} | Requires the numbers zero through nice to be entered 4 times |
( | Requires an open bracket to be entered |
[1-9]{3} or \\d{3} | Requires the numbers one through nine to be entered 3 times or zero through nine to be entered 3 times |
) | Requires a close bracket to be entered |
[1-9]{3} or \\d{3} | Requires the numbers one through nine to be entered 3 times or zero through nine to be entered 3 times |
– | Requires a dash to be entered |
[0-9]{4} or \\d{4} | Requires the numbers zero through nice to be entered 4 times |
\\d{5} | Requires the numbers one through nine to be entered 5 times |
(-\\d{4})? | The “?” makes the items within the preceding brackets optional; in this case the dash and four additional digits If you replace the ”?” with a “*”, the dash and four additional digits can be added multiple times. |
REGEX( Drivers_License__c, “\\d{3}[A-Z]{2}\\d{4}”)
\\d{3} | Requires the numbers one through nine to be entered 3 times |
[A-Z]{2} | Requires a capital letters A through Z to be entered 2 times
If you replace “[A-Z]” with “[a-z]”, it would require lower case letters. If you replace “[A-Z]” with “[A-Z][a-z]”, it would allow both upper and lower case letters. If you replace “[A-Z]” with “[C-F]”, then only upper case letters including and between C and F would be allowed. |
\\d{4} | Requires the numbers one through nine to be entered 4 times |
(\\d{4}-){3} | Requires four digits followed by a dash to be entered 3 times. This is the pattern of “9999-9999-9999-“ |
\\d{4} | Requires four digits to be entered. This is adding the last “9999” to the above string. Pay close attention to the brackets |
| | Or |
\\d{16} | Requires 16 digits |
? | The ? makes one of the two format optional |
Helpful Cheat Sheet – Get a REGEX Rule Cheat Sheet when you subscribe to my blog.
Want to learn more about how you can take advantage of REGEX validation rule to enforce data entry standards? Sign up for a free consultation and we can talk about your specific needs.