Patterns

How to ensure that user data is in the right format.
Written by Nick Laughton
Updated 1 year ago

Fields often allow you to define Patterns.  These are rules that will require users to format their data properly before entering it.  This topic can be a bit challenging because it relies on a process called "Regular Expressions" or "RegEx" in order to format the data.  RegEx can be a bit intimidating to non-programmers.  Rather than deep-dive into the nuances of RegEx, I thought it would be more helpful to include some examples that you're likely to need for your own Forms.  

You can certainly deep-dive into Regular Expressions if you don't find what you need here, but a comprehensive look into this topic is outside the scope of our Apex Forms help documentation. You can use these examples like a cookbook. You don't need to be a food scientist if you can follow the recipe.

Numbers

Only allow positive values:

^\d*\.?\d+$

Only allow negative values:

^-\d*\.?\d+$

Ensure ZIP code is 5 digits or matches ZIP + 4: 

^\d{5}(?:[-\s]\d{4})?$

Text

Don't allow more than 25 characters (and protect against sneaky hackers):

^(?!((?:.|\r|\n)*<[sS][cC][rR][iI][pP][tT]))(?:.|\r|\n){0,25}$

Ensure you have a valid email address:  

^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$

Apex Forms has a set of build in common patterned fields including Phone Number, Social Security Number, Employer Identification Number (TIN/EIN), and Email Address included in the toolkit with the patterns, validations and default help text already in place.

 

Did this answer your question?