Your search did not match any results.
Validation

Validation

Documentation

DevExtreme Data Editors provide a powerful and seamless way to perform data validation. In this demo, editors are collected in an HTML form. Each editor is accompanied by the Validator widget validating the editor against a set of specified rules. Editors are validated each time their value is changed. All validation errors are displayed in the ValidationSummary widget.

In the ASP.NET MVC demo, editors extract validation rules from data annotations attributed to the fields of the model (see the EditorsViewModel.cs file).

Note that the «Register» button here does not implement a usual onClick event handler. Instead, it has the useSubmitBehavior option set to true. This setting tells the button to validate and submit the HTML form in which it is nested, with no further configuration required.

Apply
Reset
<template> <form action="your-action" @submit="onFormSubmit($event)" > <div class="dx-fieldset"> <div class="dx-fieldset-header">Credentials</div> <div class="dx-field"> <div class="dx-field-label">Email</div> <div class="dx-field-value"> <dx-text-box> <dx-validator> <dx-required-rule message="Email is required"/> <dx-email-rule message="Email is invalid"/> <dx-async-rule :validation-callback="asyncValidation" message="Email is already registered" /> </dx-validator> </dx-text-box> </div> </div> <div class="dx-field"> <div class="dx-field-label">Password</div> <div class="dx-field-value"> <dx-text-box :value.sync="password" mode="password" > <dx-validator> <dx-required-rule message="Password is required"/> </dx-validator> </dx-text-box> </div> </div> <div class="dx-field"> <div class="dx-field-label">Confirm Password</div> <div class="dx-field-value"> <dx-text-box mode="password"> <dx-validator> <dx-required-rule message="Confirm Password is required"/> <dx-compare-rule :comparison-target="passwordComparison" message="Password and Confirm Password do not match" /> </dx-validator> </dx-text-box> </div> </div> </div> <div class="dx-fieldset"> <div class="dx-fieldset-header">Personal Data</div> <div class="dx-field"> <div class="dx-field-label">Name</div> <div class="dx-field-value"> <dx-text-box value="Peter"> <dx-validator> <dx-required-rule message="Name is required"/> <dx-pattern-rule :pattern="namePattern" message="Do not use digits in the Name" /> <dx-string-length-rule :min="2" message="Name must have at least 2 symbols" /> </dx-validator> </dx-text-box> </div> </div> <div class="dx-field"> <div class="dx-field-label">Date of birth</div> <div class="dx-field-value"> <dx-date-box invalid-date-message="The date must have the following format: MM/dd/yyyy" > <dx-validator> <dx-required-rule message="Date of birth is required"/> <dx-range-rule :max="maxDate" message="You must be at least 21 years old" /> </dx-validator> </dx-date-box> </div> </div> </div> <div class="dx-fieldset"> <div class="dx-fieldset-header">Billing address</div> <div class="dx-field"> <div class="dx-field-label">Country</div> <div class="dx-field-value"> <dx-select-box :data-source="countries"> <dx-validator> <dx-required-rule message="Country is required"/> </dx-validator> </dx-select-box> </div> </div> <div class="dx-field"> <div class="dx-field-label">City</div> <div class="dx-field-value"> <dx-text-box> <dx-validator> <dx-required-rule message="City is required"/> <dx-pattern-rule :pattern="namePattern" message="Do not use digits in the City name" /> <dx-string-length-rule :min="2" message="City must have at least 2 symbols" /> </dx-validator> </dx-text-box> </div> </div> <div class="dx-field"> <div class="dx-field-label">Address</div> <div class="dx-field-value"> <dx-text-box> <dx-validator> <dx-required-rule message="Address is required"/> </dx-validator> </dx-text-box> </div> </div> <div class="dx-field"> <div class="dx-field-label">Phone <i>(optional)</i></div> <div class="dx-field-value"> <dx-text-box :mask-rules="phoneRules" :use-masked-value="true" mask="+1 (X00) 000-0000" mask-invalid-message="The phone must have a correct USA phone format" > <dx-validator> <dx-pattern-rule :pattern="phonePattern" message="The phone must have a correct USA phone format" /> </dx-validator> </dx-text-box> </div> </div> <div> <dx-check-box id="check" :value="false" text="I agree to the Terms and Conditions" > <dx-validator> <dx-compare-rule :comparison-target="checkComparison" message="You must agree to the Terms and Conditions" /> </dx-validator> </dx-check-box> </div> </div> <div class="dx-fieldset"> <dx-validation-summary id="summary"/> <dx-button id="button" :use-submit-behavior="true" text="Register" type="success" /> </div> </form> </template> <script> import { DxSelectBox, DxCheckBox, DxTextBox, DxDateBox, DxButton, DxValidationSummary } from 'devextreme-vue'; import { DxValidator, DxRequiredRule, DxCompareRule, DxEmailRule, DxPatternRule, DxStringLengthRule, DxRangeRule, DxAsyncRule } from 'devextreme-vue/validator'; import notify from 'devextreme/ui/notify'; import service from './data.js'; const sendRequest = function(value) { const validEmail = 'test@test.com'; return new Promise((resolve) => { setTimeout(function() { resolve(value === validEmail); }, 1000); }); }; export default { components: { DxSelectBox, DxCheckBox, DxTextBox, DxDateBox, DxButton, DxValidator, DxRequiredRule, DxCompareRule, DxEmailRule, DxPatternRule, DxStringLengthRule, DxRangeRule, DxAsyncRule, DxValidationSummary }, data() { const currentDate = new Date(); return { countries: service.getCountries(), phoneRules: { X: /[02-9]/ }, password: '', namePattern: /^[^0-9]+$/, phonePattern: /^\+\s*1\s*\(\s*[02-9]\d{2}\)\s*\d{3}\s*-\s*\d{4}$/, maxDate: new Date(currentDate.setFullYear(currentDate.getFullYear() - 21)), }; }, methods: { passwordComparison: () => { return this.password; }, checkComparison: () => true, asyncValidation(params) { return sendRequest(params.value); }, onFormSubmit(e) { notify({ message: 'You have submitted the form', position: { my: 'center top', at: 'center top' } }, 'success', 3000); e.preventDefault(); } } }; </script> <style scoped> #summary { padding-left: 10px; margin-top: 20px; margin-bottom: 10px; } #button { display: block; } </style>
import Vue from 'vue'; import App from './App.vue'; new Vue({ el: '#app', components: { App }, template: '<App/>' });
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.3/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"> <span v-if="false">Loading...</span> </div> </div> </body> </html>
const countries = [ 'Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'The Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burma', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Central African Republic', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Democratic Republic of the Congo', 'Republic of the Congo', 'Costa Rica', 'Ivory Coast', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Fiji', 'Finland', 'France', 'Gabon', 'The Gambia', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Republic of Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'North Korea', 'South Korea', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Republic of Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Mauritania', 'Mauritius', 'Mexico', 'Federated States of Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique', 'Namibia', 'Nauru', 'Nepal', 'Kingdom of the Netherlands', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palau', 'State of Palestine', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', 'Romania', 'Russia', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'São Tomé and Príncipe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Sudan', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe']; export default { getCountries() { return countries; } };
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, map: { vue: 'npm:vue@2.6.3/dist/vue.esm.browser.js', 'vue-loader': 'npm:dx-systemjs-vue-browser@latest/index.js', 'devextreme': 'npm:devextreme@19.2', 'devextreme-vue': 'npm:devextreme-vue@19.2', jszip: 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', 'devexpress-gantt': 'npm:devexpress-gantt', 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, meta: { '*.vue': { loader: 'vue-loader' } }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true } });