RegularExpression class provides a comprehensive set of predefined regular expression patterns for validating common data formats. These patterns can be used with the regExp validation rule or with the Validators.regExp() static method.
Import
Basic Patterns
NUMBER
Matches strings containing only numeric digits.123, 456789, 0Does not match:
-123, 12.34, abc
Example:
ALPHABET
Matches strings containing only English letters (case-insensitive).abc, XYZ, AbCdDoes not match:
abc123, hello world, josé
ALPHA_NUMERIC
Matches strings containing only letters and numbers (no spaces or special characters).abc123, Test01, USER42Does not match:
user_123, test-01, hello world
Example:
DECIMAL
Matches numeric values including integers, decimals, and negative numbers.123, -123, 123.45, -123.45, .5, 0.99Does not match:
abc, 12.34.56, --123
Example:
Email and Names
[email protected], [email protected], [email protected]Does not match:
invalid@, @domain.com, user@domain
Example:
NAME
Matches proper names with optional spaces (English letters only).Jesus, Maria Jose, JOHN, Mary AnnDoes not match:
José, 123John, Mary Ann (double space)
Example:
NAME_ES
Matches Spanish names with accented characters and ñ.José, María Pérez, Señor MuñozDoes not match:
José123, María Pérez (double space)
Example:
URL Patterns
LINK
Matches any type of URL (www, http, or https).www.google.comhttp://example.comhttps://github.com/user/repohttp://example.com/api/auth?name=Jesus
WWW_LINK
Matches URLs starting with www.www.google.com, www.example.com/pathDoes not match:
http://google.com, example.com
HTTP_LINK
Matches URLs starting with http://http://google.com, http://example.com/apiDoes not match:
https://google.com, www.google.com
HTTPS_LINK
Matches URLs starting with https://https://google.com, https://secure.example.comDoes not match:
http://google.com, www.google.com
IP Address Patterns
IP
Matches both IPv4 and IPv6 addresses.- IPv4:
127.0.0.1,192.168.0.109,10.0.0.1 - IPv6:
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff,ffff::,ffff::ffff
IPV4
Matches only IPv4 addresses.127.0.0.1, 192.168.0.109, 10.0.0.1, 255.255.255.255Does not match:
256.1.1.1, 192.168.1, ffff::
IPV6
Matches only IPv6 addresses.ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffffffff::ffff::ffff2001:0db8:85a3::8a2e:0370:7334
Time Patterns
TIME
Matches time in both 12-hour and 24-hour formats.- 12-hour:
12:59 am,1:00 pm,01:00AM,01:00PM - 24-hour:
00:00,13:00,23:59
TIME12
Matches time in 12-hour format with AM/PM.12:59 am, 1:00 pm, 01:00AM, 11:30 PMDoes not match:
13:00, 24:00, 12:60 am
Example:
TIME24
Matches time in 24-hour format.00:00, 13:00, 23:59, 9:30, 09:30:45Does not match:
24:00, 13:60, 2:30 PM
Example:
Additional Patterns
TheRegularExpression class also includes these additional patterns:
ALPHABET_UPPERCASE- Uppercase letters onlyALPHABET_LOWERCASE- Lowercase letters onlyALPHABET_ES- Spanish letters with accentsALPHA_NUMERIC_ES- Spanish alphanumericNAME_LOWERCASE- Lowercase names onlyNAME_UPPERCASE- Uppercase names onlyNAME_CAPITALIZE- Capitalized names (e.g., “John Doe”)NAME_LOWERCASE_ES- Spanish lowercase namesNAME_UPPERCASE_ES- Spanish uppercase namesNAME_CAPITALIZE_ES- Spanish capitalized namesINTEGER- Integer numbers (positive or negative)SPECIAL_CHARACTERS- Special character validationPHONE- Phone number patternsCARD- Credit card number patterns
Using with Validators
Regular expressions can be used in two ways:With Validation Rules
With Static Methods
Custom Regular Expressions
You can also use custom regex patterns with theregExp rule:
Common Use Cases
Form Validation
API Input Validation
Time Entry Validation
URL Validation
Related
- Validators - Static validation methods
- Alphabets - Predefined character sets
- Format Rules - Format validation rules
- Validator - Main validation class