Version 6.0 Released!

Click to checkout the new features

Old Documentation
You are browsing documentation for an old version of Tabulator. Consider upgrading your project to Tabulator 6.0

Data Validation

Overview

Validators are used to ensure that any user input into your editable cells matches your requirements.

Validators can be applied by using the validator property in a columns definition object (see Define Columns for more details).

{title:"Rating", field:"rating", editor:"input", validator:"required"}

When using validators that take properties you can pass in an object:

{title:"Rating", field:"rating", editor:"input", validator:{
	type:"max",
	parameters:5,
}}

Or you can use the shorthand notation, separating the type and parameter with a : symbol:

{title:"Rating", field:"rating", editor:"input", validator:"max:5"}

Validator Functions

Built In Validators

Tabulator has a wide variety of built in validators:

Note: For a guide to adding your own validators to this list, have a look at the Extending Tabulator section.

Note By default all validators, except the required validator will approve any empty value (ie. empty string, null or undefined). to ensure empty values are rejected you should use the required validator.

Required

The required validator allows values that are not null or an empty string

{title:"Example", field:"example", validator:"required"}

Unique

The unique validator allows values that do not match the value of any other cell in this column

{title:"Example", field:"example", validator:"unique"}

Integer

The integer validator allows values that are valid integers

{title:"Example", field:"example", validator:"integer"}

Float

The float validator allows values that are valid floats

{title:"Example", field:"example", validator:"float"}

Numeric

The numeric validator allows values that are valid numbers

{title:"Example", field:"example", validator:"numeric"}

String

The string validator allows values that are a non-numeric string

{title:"Example", field:"example", validator:"string"}

Minimum Numeric Value

The min validator allows numeric values that are greater than or equal to parameter

 {title:"Example", field:"example", validator:"min:5"} \\value must be greater than or equal to 5

Maximum Numeric Value

The max validator allows numeric values that are less than or equal to parameter

 {title:"Example", field:"example", validator:"max:5"} \\value must be less than or equal to 5

Minimum String Length

The minLength validator allows string values that have a length greater than or equal to parameter

 {title:"minLength", field:"example", validator:"minLength:5"} \\value must have a length greater than or equal to 5

Maximum String Length

The maxLength validator allows string values that have a length less than or equal to parameter

 {title:"Example", field:"example", validator:"maxLength:5"} \\value must have a length less than or equal to 5

In List

The in validator allows that values that match a value from the | delimited string in the parameter

 {title:"Example", field:"example", validator:"in:red|green|blue"} \\value must be 'red', 'green' or 'blue'

Regular Expression

The regex validator allows values that match the supplied regex

 {title:"Example", field:"example", validator:"regex:\\.com$"} \\allow strings that end in '.com'

Validation Failure

If the validation fails the tabulator-validation-fail class will be applied to the cell and the validationFailed callback will be triggered.

The user will not be able to leave the a cell that has failed vailidation until they input a valid value or cancel the edit (press escape)

Custom Validator Functions

If you want to add your own custom validation functions, you can pass a function to the validator property. It should return true if the value passes validation and false if it fails:

//validator to prevent values divisible by the provided divisor
var noDivide = function(cell, value, parameters){
	//cell - the cell component for the edited cell
	//value - the new input value of the cell
	//parameters - the parameters passed in with the validator

	return value % parameters.divisor; //don't allow values divisible by divisor ;
}

//in your column definition for the column
{title:"Age", field:"age", editor:"input", validator:[
	{
		type:noDivide,
		parameters:{
			divisor:5,
		}
	}
]}

Applying Multiple Validators

You can use multiple validators on the same column by passing an array to the validator property

{title:"Rating", field:"rating", editor:"input", validator:["required", "max:5"]}

Callbacks

A range of callbacks are available for validation. See the Validation Callbacks section for more information.

Donate