Validation Rules NumericRule

A validation rule that demands that the validated field has a numeric value.

Type: Object

Show Example:
AngularJS
Knockout
jQuery

In this example, the 'numeric' rule is applied to the editor. This rule demands that the editor has a numeric value. To check this rule, specify a string in the editor.

<div style="height:200px;max-width:200px;margin:0px auto" ng-controller="demoController">
    <div dx-text-box="{ bindingOptions: {value: 'phone'},  placeholder: 'Input your phone...' }" 
        dx-validator="{ validationRules: [ { type: 'numeric' } ] }">        
    </div>
	<div dx-validation-summary="{ }"></div>
	<div dx-button="{ text: 'Submit', onClick: submit }"></div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.phone = "";
    $scope.submit = function (params) {
        var result = params.validationGroup.validate();
        if (result.isValid) {
            DevExpress.ui.notify({
                message: "Your phone number is submitted.",
                position: {
                    my: "left top",
                    at: "left top",
                }
            }, "Success", 3000);
        }
    }
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});

In this example, the 'numeric' rule is applied to the editor. This rule demands that the editor has a numeric value. To check this rule, specify a string in the editor.

<div style="height:200px;max-width:200px;margin:0px auto">
	<div data-bind="dxTextBox: { value: phone, placeholder: 'Input your phone...' },
		dxValidator: {  validationRules: [{ type: 'numeric' }] }">
	</div>
	<div data-bind="dxValidationSummary: { }"></div>
	<div data-bind="dxButton: { text: 'Submit', onClick: submit }"></div>
</div>
var myViewModel = {
    phone: ko.observable(""),
    submit: function (params) {
        var result = params.validationGroup.validate();
        if (result.isValid) {
            DevExpress.ui.notify({
                message: "Your phone number is submitted.",
                position: {
                    my: "left top",
                    at: "left top",
                }
            }, "Success", 3000);
        }
    }
}
ko.applyBindings(myViewModel);

In this example, the 'numeric' rule is applied to the editor. This rule demands that the editor has a numeric value. To check this rule, specify a string in the editor.

<div style="height:200px;max-width:200px;margin:0px auto">
    <div id="phone"></div>
    <div id="summary"></div>
    <div id="button"></div>
</div>
$(function () {
    $("#phone").dxTextBox({
        value: null, placeholder: 'Input your phone...'
    }).dxValidator({
        validationRules: [ { type: 'numeric' } ]
    });
    $("#summary").dxValidationSummary({});
    $("#button").dxButton({
        text: 'Submit',
        onClick: function (params) {
            var result = params.validationGroup.validate();
            if (result.isValid) {
                DevExpress.ui.notify({
                    message: "Your phone number is submitted.",
                    position: {
                        my: "left top",
                        at: "left top",
                    }
                }, "Success", 3000);
            }
        }
    });
});

message

Specifies the message that is shown for end-users if the current rule is broken.

Type: String
Default Value: 'Value should be a number'

You do not have to specify this field. In this instance, a default message will be shown. To include the name of the validated editor into the default validation message as a subject, set the name field of the dxValidator object.

type

Specifies the type of the current rule.

Type: String
Accepted Values: 'numeric'

Set this field to 'numeric' to define a rule that will be broken if the validated value is not numeric.