Easy Tutorial
❮ Jeasyui Ref Plugins Jeasyui App Crud2 ❯

jQuery EasyUI Form Plugin - Validatebox Validation Box



Override the default defaults with $.fn.validatebox.defaults.

The validatebox is designed to validate form input fields. If the user enters an invalid value, it will change the background color, display a warning icon, and a prompt message. The validatebox can be integrated with the form plugin to prevent submission of invalid fields.

Dependencies

Usage

Create a validatebox from markup.

<input id="vv" class="easyui-validatebox" data-options="required:true,validType:'email'">

Create a validatebox using JavaScript.

<input id="vv">
$('#vv').validatebox({
    required: true,
    validType: 'email'
});

Check if the password and re-entered password are the same.

// extend the 'equals' rule
$.extend($.fn.validatebox.defaults.rules, {
    equals: {
        validator: function(value,param){
            return value == $(param[0]).val();
        },
        message: 'Fields do not match.'
    }
});
<input id="pwd" name="pwd" type="password" class="easyui-validatebox" data-options="required:true">
<input id="rpwd" name="rpwd" type="password" class="easyui-validatebox"
    required="required" validType="equals['#pwd']">

Validation Rules

Validation rules are defined using the required and validType attributes. Here are the implemented rules:

To customize validation rules, override $.fn.validatebox.defaults.rules to define a validation function and an invalid message. For example, define a minLength validation type:

$.extend($.fn.validatebox.defaults.rules, {
    minLength: {
        validator: function(value, param){
            return value.length >= param[0];
        },
        message: 'Please enter at least {0} characters.'
    }
});

Now you can use this minLength validation type to define an input box that requires at least 5 characters:

<input class="easyui-validatebox" data-options="validType:'minLength[5]'">

Properties

Name Type Description Default Value
required boolean Defines if the field should be entered. false
validType string,array Defines the validation type of the field, such as email, url, etc. Possible values: <br>1. Validation type string, applies a single validation rule. <br>2. Validation type array, applies multiple validation rules. Multiple validation rules on a single field are available since version 1.3.2. <br> <br>Code example: <input class="easyui-validatebox" data-options="required:true,validType:'url'"><br><input class="easyui-validatebox" data-options="<br> required:true,<br> validType:['email','length[0,20]']<br>"> null
delay number Delays the validation of the last input value. This property is available since version 1.3.2. 200
missingMessage string The prompt text that appears when the text box is empty. This field is required.
invalidMessage string The prompt text that appears when the text box content is invalid. null
tipPosition string Defines the position of the prompt message when the text box content is invalid. Possible values: 'left', 'right'. This property is available since version 1.3.2. right
deltaX number The tooltip offset in the X direction. This property is available since version 1.3.3. 0
novalidate boolean When set to true, disables validation. This property is available since version 1.3.4. false

Methods

Name Parameters Description
destroy none Removes and destroys the component.
validate none Performs validation to determine if the text box content is valid.
isValid none Calls the validate method and returns the validation result, true or false.
enableValidation none Enables validation. This method is available since version 1.3.4.
disableValidation none Disables validation. This method is available since version 1.3.4.
❮ Jeasyui Ref Plugins Jeasyui App Crud2 ❯