Validation
Validating fields (text or other) is crucial for ensuring that data entered by users meets specific criteria or formats and for maintaining data integrity and security.
In you can use regular expressions (regex) for text validation. They allow for pattern matching and can enforce complex rules for text fields such as email addresses, phone numbers, usernames, passwords, and more. When applied to text validation, regex can be used to check if the input text matches the desired format. If it is not valid, an invalid message is displayed.
In you combine a JSONata expression with a Regex expressions to create a validation pattern and provide a message if the pattern does not match.
- JSONata expression - [email protected]
- Regex expression - /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
- Validation message - not an email
Combine the three above to validate an email address in the text-field component.
Here are some common validation expressions to create and use for text field validation.
Validation | Expected result |
---|---|
Phone number | +271234556789 |
Email | |
Credit Card | Typically 13-16 digits, with spaces or dashes optional, and includes checks for Visa, MasterCard, American Express, and Discover. 1111-1111-1111-1111 or 1111 1111 1111 1111 |
5-digit codes, e.g. 10036 | |
XXX-XX-XXXX | |
AA123456C | |
23/07/2024 | |
03/28/2023 | |
25 July 2024 | |
2024/08/30 | |
Decimal | 111,25 |
12:15 AM or 08:45 PM | |
08:10 | |
01:00 | |
URL | example.com or https://example.com |
ISBN | 978-1-4302-1998-9 |
JohnSmith | |
John Smith | |
56575 76 6 |