Vue Validator - PatternRule
A validation rule that requires 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.
NOTE
If you apply a pattern rule to a DateBox component, specify dateSerializationFormat so that the format of the validated value is a string.
See Also
message
Specifies the message that is shown if the rule is broken.
Type:
Default Value: 'Value does not match pattern'
You can configure an error message in the following ways:
Specify a hard-coded message:
App.vue- <template>
- <DxTextBox>
- <DxValidator>
- <DxPatternRule
- message="My custom message"
- />
- </DxValidator>
- </DxTextBox>
- </template>
- <script setup lang="ts">
- import { DxTextBox } from 'devextreme-vue/text-box';
- import { DxValidator, DxPatternRule } from 'devextreme-vue/validator';
- </script>
Hide the message:
App.vue- <template>
- <DxTextBox>
- <DxValidator>
- <DxPatternRule
- message=""
- />
- </DxValidator>
- </DxTextBox>
- </template>
Display the editor's name in the default message (for instance, "Phone number does not match pattern"):
App.vue- <template>
- <DxTextBox>
- <DxValidator name="Phone number">
- <DxPatternRule />
- </DxValidator>
- </DxTextBox>
- </template>