CRMJettyBack to crmjetty.comContact us
Menu
Docs / Guides

CRMJetty Portal

Works with
Docs / Dynamics 365

Dynamics 365 Customer Portalv6.3.0

Docs / Salesforce

Salesforce Customer Portalv6.3.0

Docs / Business Central

Business Central Portal

Guides / Forms

How to Add Regex Validation to Form Fields

5 min readUpdated
Short answerIn Design → Form Builder, open the settings of a string field, enter a regular expression in Enter Regex Pattern and an error message in Enter Regex Validation Message, then save and publish the form. Portal users can't submit a value that doesn't match.

Regex (regular expression) validation makes a portal form field accept only values in a set format, such as a postal code, a phone number or an ID like ABC-1234. Portal users who enter a value in the wrong format see your error message and can’t submit the form until they fix it. This keeps the data that reaches your CRM consistent.

Before you start

Regex settings

Setting What to enter
Enter Regex Pattern The regular expression the value must match. It defines the required format, such as digits only or a fixed ID format.
Enter Regex Validation Message The error message portal users see when their value doesn’t match. Say what the correct format is, for example “Enter a 5-digit ZIP code”.

Steps

  1. Go to Design → Form Builder.
  2. Select Edit on the form.
  3. Select the Settings icon on the string field you want to validate. The Field Configuration panel opens.
  4. In Enter Regex Pattern, enter your pattern. See the examples below.
  5. In Enter Regex Validation Message, enter the message portal users see when the value is wrong.
  6. Select Save.
  7. Publish the form.
  8. Open the form in the portal and test it with a valid and an invalid value.
Field Configuration panel of a string field with Enter Regex Pattern set to ^[0-9]{5}$ and Enter Regex Validation Message filled in

Example patterns

Each pattern starts with ^ and ends with $, so the whole value must match, not just part of it.

Use it for Pattern Accepts Rejects
US ZIP code ^[0-9]{5}$ 90210 9021, 90210-1234
Order or ticket ID ^[A-Z]{3}-[0-9]{4}$ ABC-1234 abc-1234, AB-1234
Account code of 6 to 10 letters or digits ^[A-Za-z0-9]{6,10}$ AC12345 AC-123, AB12
Phone number ^\+?[0-9]{7,15}$ +14155550123, 4155550123 415-555-0123, +1 415 555
Email address (basic check) ^[^@\s]+@[^@\s]+\.[^@\s]+$ name@example.com name@example, name example.com

What each pattern means:

Regex quick reference

Symbol Meaning
^ and $ Start and end of the value. Use both so the whole value must match.
[0-9] Any one digit.
[A-Z], [a-z] Any one capital letter, any one lowercase letter.
[^@\s] Any one character except @ and white space.
{5}, {6,10} Exactly 5 of the item before it; 6 to 10 of the item before it.
+ One or more of the item before it.
? The item before it is optional (zero or one).
\ Makes the next character literal, for example \+ for a plus sign or \. for a dot.

Tip: Test a new pattern with sample values before you use it on a live page, for example on a test page that only admins know about. Draft forms don’t appear in the portal, so you can’t test the pattern on a draft. A pattern that is too strict blocks portal users from submitting the form.

Troubleshooting

Valid values are rejected: Check the pattern for unescaped special characters. A plus sign or dot must be written \+ or \. to match the character itself. Also check for spaces, dashes or lowercase letters in the value that the pattern doesn’t allow.

Invalid values are accepted: Make sure the pattern starts with ^ and ends with $. Without them, a value may pass if any part of it matches.

The validation doesn’t run: Check that you saved the field settings and published the form. Draft changes don’t appear in the portal.

Did this solve it?No, contact support