Search 3B Knowledge Base
- Home
- Features
- Data Validation
- Useful REGEX sniplets
What is this article about?
3B Forms support custom field validation through the use of Javascript RegExt. This is a simple piece of code which allows you to control the format of the data inputted on your forms. Below, you can find a list of useful/most used RegEx snipplets that you can just add to your forms.
How do I add Custom RegExt to fields?
Just jump over to edit any valid field (Text Fields, Date/Time Fields) from the Form Builder. In the field settings pop-up, right at the bottom, you will see a panel such as this one:
The last option in this panel is called Custom Regular Expression Formula which is where you need to input your RegEx formulas
Examples:
1. US Social Security Number
Formula | |
^(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$ |
|
Matches | |
|
2. UK National Insurance Number
Formula | |
|
|
Matches | |
|
3. US Post Code/ZIP Format
Formula | |
|
|
Matches | |
|
4. UK Post Code Format
Formula | |
([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))\s?[0-9][A-Za-z]{2}) |
|
Matches | |
|
5. Simple Password Validation
Formula | |
/^[a-z0-9_-]{6,18}$/ |
|
Matches | |
Matching 6 to 18 letters, numbers, underscores, or hyphens – no special charecters. |
6. Matching an Email
Formula | |
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ |
|
Matches | |
We begin by telling the parser to find the beginning of the string (^). Inside the first group, we match one or more lowercase letters, numbers, underscores, dots, or hyphens. I have escaped the dot because a non-escaped dot means any character. Directly after that, there must be an at sign. Next is the domain name which must be: one or more lowercase letters, numbers, underscores, dots, or hyphens. Then another (escaped) dot, with the extension being two to six letters or dots. I have 2 to 6 because of the country specific TLD’s (.ny.us or .co.uk). Finally, we want the end of the string ($). |
7. Matching a URL
Formula | |
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ |
|
Matches | |
This regex is almost like taking the ending part of the above regex, slapping it between “http://” and some file structure at the end. It sounds a lot simpler than it really is. To start off, we search for the beginning of the line with the caret.
The first capturing group is all option. It allows the URL to begin with “http://”, “https://”, or neither of them. I have a question mark after the s to allow URL’s that have http or https. In order to make this entire group optional, I just added a question mark to the end of it. Next is the domain name: one or more numbers, letters, dots, or hypens followed by another dot then two to six letters or dots. The following section is the optional files and directories. Inside the group, we want to match any number of forward slashes, letters, numbers, underscores, spaces, dots, or hyphens. Then we say that this group can be matched as many times as we want. Pretty much this allows multiple directories to be matched along with a file at the end. I have used the star instead of the question mark because the star says zero or more, not zero or one. If a question mark was to be used there, only one file/directory would be able to be matched. Then a trailing slash is matched, but it can be optional. Finally we end with the end of the line. |
-
-
- 1.0 - 1.2 Aloha
- 1.10 Bodhi Tree
- 1.11 Baobab Tree
- 1.12 Baobab Tree
- 1.15 Baobab Tree
- 1.16 - Apricot Tree
- 1.19 Bonzai Tree
- 1.20 Maple
- 1.21 Palm Tree
- 1.22 Mandarin
- 1.23 Ginko
- 1.24 Duran
- 1.25 Fir
- 1.27 Lychee Tree
- 1.3 Beech
- 1.34 Stewartia
- 1.35 - 1.42 Tree of life
- 1.35 Horse Chestnut
- 1.4 Almond
- 1.43 General Sherman
- 1.47 General Sherman
- 1.48 General Sherman
- 1.5 Rosewood
- 1.53 Hornbeam
- 1.6 Cherry Wood
- 1.7 Fault Tree
- 1.7 Mango Tree
- 1.8 Coconut
- Show all articles ( 13 ) Collapse Articles
-
-
-
-
- Articles coming soon
-
- Articles coming soon
-
- Articles coming soon