Regex expressions
By combining regular (regex) expressions in your JSONata expressions in , you can create complex patterns to match specific strings of text. Regex expressions are a sequence of characters that define a search pattern. It is powerful when used in text processing to find, replace, or validate strings of text. Some common uses of regex include:
- Validating email addresses or phone numbers
- Extracting specific information from a text file or document
- Reformatting data to match a specific pattern or structure
The JSONata + regex examples below create validation for text-fields in a form.
Phone number validation
Expected results: Between 9 and 13 numbers with no spaces, can include a symbol for dialing code, e.g., +271234556789.
Email validation
Expected result: [email protected]
Credit card validation
Expected result: Typically 13-16 digits, with spaces or dashes optional, and includes checks for Visa, MasterCard, American Express, and Discover. E.g. 1111-1111-1111-1111 or 1111 1111 1111 1111.
ZIP/Postal code (US) validation
Expected result: 5-digit codes, e.g. 10036.
Social Security Number (US) validation
Expected result: XXX-XX-XXXX
National Insurance Number (UK) validation
Expected result: AA123456C
US Date (DD/MM/YYYY) validation
Expected result: DD/MM/YYYY, e.g. 23/07/2024.
Date (MM/DD/YYYY) validation
Expected result: MM/DD/YYYY, e.g. 03/28/2023.
Date (DD Month YYYY) validation
Expected result: DD Month YYYY, e.g. 25 July 2024.
Date (yyyy/mm/dd) validation
Expected result: yyyy/mm/dd, e.g. 2024/08/30.
Decimal validation
Expected result: 1234,00
Time (H:MM AM/PM) validation
Expected result: H:MM AM/PM e.g. 12:15 AM or 08:45 PM
Time (MM:SS / or HH:MM) validation
Expected result: MM:SS / or HH:MM, e.g. 08:10.
Time in 24-hour format
Expected result: 01:00
URL validation
Expected result: example.com or http://example.com
ISBN validation
Expected result: 978-1-4302-1998-9
Strict Alpha Numeric validation
Expected result: JohnSmith
Alpha Numeric with spaces allowed validation
Expected result: John Smith
validation of numbers and Spaces only
Expected result: 56575 76 6