Custom Regular Expressions List
Useful Regular Expressions
RegEx Name | RegEx Code | Valid Input |
---|---|---|
National Insurance Number (UK) | /^(?!BG|GB|NK|KN|TN|NT|ZZ)[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z](?:\s*\d{2}){3}\s*[A-D]$/ | AA123456C |
Positive Number | /^\d*\.?\d+$/ | 1 |
Negative Number | /^-\d*\.?\d+$/ | -1 |
Time in 24-hour Format | /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/ | 01:00 |
URL | /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ | example.com or http://example.com |
ISBN | /((978[\--– ])?[0-9][0-9\--– ]{10}[\--– ][0-9xX])|((978)?[0-9]{9}[0-9Xx])/ | 978-1-4302-1998-9 |
Saudi Mobile | /05\d{8}/ | 0591234567 |
Two Decimal Places (Only) | /^[0-9]+(\.[0-9]{1,2})?$/ | 2.99 |
Two Decimal Places Alternative | /^((\d|[1-9]\d+)(\.\d{1,2})?|\.\d{1,2})$/ | 2.99 |
Single Decimal Place | /^((\d|[1-9]\d+)(\.\d{1})?|\.\d{1})$/ | 2.5 |
Custom Email Address | /.*@youremail.com/ | any@youremail.com |
Decimals | /(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)/ | 3.78, 23.85, 23.5192 |
Hex | /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ | #FFFFFF |
IP Address | /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ | 73.60.124.136 |
Currency ( "$" optional and the "cents" is required) | /^\$[+-]?[0-9]{1,3}(?:,?[0-9]{3}).[0-9]{2}$/ | 3.78, 23.85 |
Currency ( "$" and the "cents" is required) | /^\$[+-]?[0-9]{1,3}(?:,?[0-9]{3})*.[0-9]{2}$/ | 3.78, 23.85 |
Exclude a string that contains ".org" | /^((?!.org).)*$/ | test.com, test@yahoo.com.ph test@gmail.com |
Strict Alpha Numeric | /^[a-zA-Z0-9]+$/ | JamesDean |
Alpha Numeric with spaces allowed | /^[a-z\d\-_\s]+$/ | James Dean |
Numbers and Spaces Only | /^[0-9\s]*$/ | 56575 76 6 |
Time MM:SS / or HH:MM | /^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$/ | 10:59 |
How to set Custom RegEx Validation:
Step 1: Click the Field where you want to set the Custom RegEx Validation
Step 2: Click Field Validation Settings > Validation > Choose Custom RegEx
Step 3: Copy the Code and Paste it on the Validation Regex Property under the Field Validation Settings.
Have more questions? Submit a request
Article is closed for comments.
0 Comments