regexIsMatch() : Test Regular Expression
On this page
Summary
Test if a string matches a regular expression pattern.
Signature
regexIsMatch(str, pattern)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
str |
String | Yes | The string to test |
pattern |
String | Yes | The regular expression pattern |
Returns
Type: Boolean
true if the string matches the pattern, false otherwise.
Examples
Email Validation
Data:
doc.Params["model"] = new {
email = "user@example.com"
};
Output:
<p class="valid">Valid email: user@example.com</p>
Phone Number Format
Data:
doc.Params["model"] = new {
phone = "555-123-4567"
};
Output:
<p>US Format: 555-123-4567</p>
Postal Code Validation
Contains Digits
Alphanumeric Check
Data:
doc.Params["model"] = new {
code = "ABC123"
};
Output:
<p>Valid code: ABC123</p>
Notes
- Uses .NET regex syntax
- Backslashes must be escaped:
\\dfor digit,\\wfor word character - Case-sensitive by default
- Returns true if any part of string matches (use ^ and $ for exact match)
- For extracting matches, use
regexMatches() - For replacement, use
regexSwap() - More powerful than
contains()but slower
Common Patterns
| Pattern | Description |
|---|---|
^\\d+$ |
Only digits |
^[A-Za-z]+$ |
Only letters |
^[A-Za-z0-9]+$ |
Alphanumeric |
^.+@.+\\..+$ |
Basic email |
^\\d{3}-\\d{3}-\\d{4}$ |
US phone (XXX-XXX-XXXX) |
^\\d{5}$ |
US ZIP code |