How to Use Custom Validation
תוכן זה אינו זמין עדיין בשפה שלך.
Custom validation allows you to define specific rules for input fields using regular expressions (regex).
This is how the custom validation input looks for the end user:
Basic Regex Patterns
Section titled “Basic Regex Patterns”-
Letters only:
^[A-Za-z]+$
- Matches any string containing only letters (A-Z or a-z).
-
Numbers only:
^\\d+$
- Matches any string containing only digits.
-
Letters and numbers:
^[A-Za-z0-9]+$
- Matches any string containing letters and/or numbers.
-
Email address:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$
- Matches most common email address formats.
-
Phone number:
^\\+?[\\d\\s-]{7,}$
- Matches phone numbers with an optional
+
at the start, and allows digits, spaces, and hyphens.
- Matches phone numbers with an optional
-
UK Postcode:
^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s*\\d[a-zA-Z]{2}$
Quantifiers
Section titled “Quantifiers”{n}
: Exactly n times{n,}
: n or more times{n,m}
: Between n and m times*
: 0 or more times+
: 1 or more times?
: 0 or 1 time
Examples
Section titled “Examples”-
3-10 letters:
^[A-Za-z]{3,10}$
- Matches strings with 3 to 10 letters.
-
US Zip Code:
^\\d{5}(-\\d{4})?$
- Matches 5-digit zip codes and optional 4-digit extensions.
-
Date (YYYY-MM-DD):
^\\d{4}-\\d{2}-\\d{2}$
- Matches dates in the format YYYY-MM-DD.
For more advanced patterns and detailed explanations, visit RegExr.