The Firmhouse payment page has some general rules in place to verify that your customers fill in all the required fields correctly, like an email address.
Depending on your offering, it's possible you do not want everyone to be able to sign up. You might want to filter subscribers to meet your specific criteria, for example, when you only deliver your product in a specific geographic region.
What are Custom Form Field Validations?
With the custom form field validations you can define specific requirements for new customers. These validations check if the data entered by the customer, are within the criteria you allowed. For instance area codes, Phone number is mobile, etc. During signup we will automatically verify this for you.
Please note: This is an advanced feature powered by Regular expressions (regex), so it may seem a little complicated to set up if you have not worked with the regular expressions before, but do not worry! We will walk you through some examples in this article so you can create your own rules too. And if you need further help, do not hesitate to reach out to our friendly customer support! We are here to help.
This feature can be accessed via the "Checkout" menu, "Extra fields and Validations" submenu on the left. Here you can Create, Edit and Delete a custom form field validation.
Creating a new validation
1. Select a form field
You can create a validation for any core field of the Firmhouse checkout page form:
Zipcode
Email
Phone Number
City
Address
House Number
2. Write a regular expression
Write a pattern that the user's input should match against.
Scroll down to the end of this article to see examples for each available form field!
We support 3 regular expression options that you might need for more advanced patterns:
i - ignore case
x - ignore whitespace in the regular expression
m -make dot match newlines in the regular expression
You can select multiple options or skip it if you do not need any of them.
3. Add an error message
Write some error text to let your users know why they cannot sign up to your subscription.
You can create multiple validations for the same field and we will show error messages accordingly.
4. Test your regular expression
We added a little playground so you could test your regex when you are creating one. Go to Playground section and enter some value you want to test and you will see if it is valid or not right away.
For example, regex from the screenshot above ^12345$ will match value of 12345
but will not match value of 12347
Example regular expressions for core form fields
Zipcode
To match a few zipcodes, one of the options is to add your selected zipcodes as a in the following format:
^(12345|12346|12347|23467)$
This is a very simple and convenient way to create a pattern for any collection. It will create a hard limitation to only allow these numbers.
TIP: When building a regular expression, start your regex with ^, end it with $, and split values with |.
^ - means the start of the string, so that no additional characters are allowed before your value. (12345 is allowed, 112345 is not)
$ - means the end of the string, so that no additional characters are allowed after your value. (12345 is allowed, 123451 is not)
To match a big range of numbers you can create a bit smarter regex, for example:
^(120[3-5][0-9][0-9])$
It will cover all the numbers in this range: 120300 - 120599.
To cover all zipcodes for a particular country, you might need to use a more complex pattern. Luckily, there are many sources to find on the internet that provide regex patterns you can copy and paste.
Here are some examples for different countries zipcode matching you can use:
US:
^\b\d{5}\b(?:[- ]{1}\d{4})?$
It will allow values in the format of
"NNNNN (optionally NNNNN-NNNN)"
Where N is any number.
The Netherlands:
^\d{4}\s{0,1}[A-Za-z]{2}$
It will allow values in the format of
"NNNN AA"
Where N is any number and AA is letters
The United Kingdom:
^[A-Za-z]{1,2}\\d([A-Za-z]|\\d)\\d[A-Za-z]{2}$
It will allow values in the format of
"A(A)N(A/N)NAA (A[A]N[A/N] NAA)"
Where N is any number, A is letter and optional characters are in ().
China:
^\d{6}$
It will allow values in the format of
"NNNNNN"
Where N is any number.
You might want to only allow users with emails at a particular domain name. It could be done as simple as this:
^.+@example.com$
. (dot) - means any character
+ (plus) - means any amount of times
With this pattern, any amount of characters (more than 0) is allowed before "@example.com".
Phone number
You might need to allow users to register only with country specific phone numbers. As for country specific zipcode patterns, there are many sources for country specific regex that you can copy and paste.
For example, US numbers with formats (123)123-1234 and 123-123-1234 could be achieved with this regex:
^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}$
City
If you want to limit your delivery area to specific cities, you can setup a simple regex similar to example with zipcodes.
For example, if you want to allow only users from Amsterdam and Rotterdam to sign up, you can do it with this pattern:
^(Amsterdam|Rotterdam)$
Address
If you want to your customers to write their address in a specific address list, you can setup a simple regex similar to example with zipcodes.
^(Green street|Main street)$
To make your regex case insensitive (to allow both "Green street", "green street" and "Green Street"), select "ignore case" option when creating your validation.
If you want your customers to write their address in some specific format, you can do it with the following regex
^[a-zA-Z]+, \d+$
This will only allow address to be in the following format:
any amount of case-insensitive letter-characters (more than 0) followed by a comma(,) followed by a space ( ), followed by any amount of digits
House number
If you want to limit your delivery area to specific house numbers, you can setup a simple regex similar to example with zipcodes.
^(11|15)$
This will allow only users with House number of 11 or 15 to sign up, but not any other.
^(11-15)$
This will allow only users with House number in the range between 11 and 15 (inclusive) to sign up.