JavaScript/jQuery Validator - PatternRule
A validation rule that demands that the validated field match a specified pattern.
import { PatternRule } from "devextreme/common"
Type:
To specify the regular expression that the validated field must match, set the rule's pattern configuration property.
See Also
message
Specifies the message that is shown if the rule is broken.
Type:
Default Value: 'Value does not match pattern'
An error message can be specified as follows:
Hard-code the message
index.js- $(function() {
- $("#textBox").dxTextBox({ ... })
- .dxValidator({
- type: "pattern",
- message: "My custom message"
- });
- });
Hide the message
index.js- $(function() {
- $("#textBox").dxTextBox({ ... })
- .dxValidator({
- type: "pattern",
- message: ""
- });
- });
Display the editor's name in the message
index.js- $(function() {
- $("#textBox").dxTextBox({ ... })
- .dxValidator({
- name: "Phone number", // The error message will be "Phone number does not match pattern"
- validationRules: [{
- type: "pattern"
- }]
- });
- });
pattern
Specifies the regular expression that the validated value must match.
NOTE
If your pattern is a string, escape the backslash. For example, the following pattern matches a character other than white space:
Code
- pattern: '\\S'