Validations available


The plugin has the following built-in validation rules, which must be used within data-dj-validator attribute:


Required field

The “required” attribute of HTML5 is used to verify that the field is not empty or contains only spaces:

<input type="text" required=”required”/>

Validate texts:

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Any text

text, [min] , [max]

min : minimum characters allowed.
max : maximum characters allowed.

Accept any character, validating only length of text. The maximum size can be omitted (*).

data-dj-validator="text,3,12"
data-dj-validator="text,3,*"

Alphabetic text

atext, [min] , [max]

min : minimum characters allowed.
max : maximum characters allowed.

Accepts alphabetic characters in upper and lower case, including spaces, the letter ñ and accented characters (á, é, í, ó, ú, ç, ü), also validating length of text. The maximum size can be omitted (*).

data-dj-validator="atext,3,12"
data-dj-validator="atext,3,*"

Alphabetical text and digits

antext, [min] , [max]

min : minimum characters allowed.
max : maximum characters allowed.

Accept upper and lower case alphabetic digits and characters, including spaces, the letter ñ and the accented characters (á, é, í, ó, ú, ç, ü), also validating length of text. The maximum size can be omitted (*).

data-dj-validator="antext,3,12"
data-dj-validator="antext,3,*"

Word (text without spaces)

word, [min] , [max]

min : minimum characters allowed.
max : maximum characters allowed.

Accept any character except spaces, also validating length of text. The maximum size can be omitted (*).

data-dj-validator="word,4,8"
data-dj-validator="word,4,*"

Digits only

dig, [min] , [max]

min : minimum number of digits allowed.
max : maximum digits allowed.

Accept a digit text, validating the length of the digit string. The maximum size can be omitted (*).

data-dj-validator="dig,4,8"
data-dj-validator="dig,4,*"

Validate number fields

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Integer numbers

int, [min] , [max]

min : minimum value allowed.
max : maximum value allowed.

Accept only positive or negative integers (accept the "-" sign ), also validating the value of the whole number. The maximum and/or minimum value of the number can be omitted (*).

data-dj-validator="int,1,*"
data-dj-validator="int,*,100"
data-dj-validator="int,*,*"
data-dj-validator="int,-100,-1"

Real numbers

num, [min] , [max]

min : minimum value allowed.
max : maximum value allowed.

Accept any type of real number, using the point (.) as decimal separator, accept "-" sign, also validating the number value. The maximum and/or minimum value can be omitted (*).

data-dj-validator="num,1,*"
data-dj-validator="num,*,10.5"
data-dj-validator="num,*,*"
data-dj-validator="num,-1.5,1.5"

Common validations

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Email address

email, [max]

max : maximum characters allowed.

Accept valid email addresses of any domain level, also validating maximum number of characters optionally(*).

data-dj-validator="email,30"
data-dj-validator="email,*"

Web address (url)

url, [max]

max : maximum characters allowed.

Accepts URLs of the HTTP, HTTPS, FTP and FTPS protocols, also validating maximum number of characters optionally(*).

data-dj-validator="url,50"
data-dj-validator="url,*"

Phone number

phone

NONE

Accepts phone numbers in the following formats:
+591 70229728
70229728
The "+" sign is optional, the separator can be "space" or "-", the code can have 2 to 3 digits and the number can have 5 to 12 digits.

data-dj-validator="phone"

IP adress

Ip, [type]

type (optional): ipv4 or ipv6

Accepts IP addresses that can be v4 or v6 depending on the specified parameter, if not specified verify both.

data-dj-validator="ip"
data-dj-validator="ip,v4"
data-dj-validator="ip,v6"

Validate files

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Validate files

file, [min], [max], [min_size], [max_size], [type1 | type2 ..]

min : minimum number of files to select.
max : maximum number of files to select
min_size : Minimum size of selected files (kb).
max_size : Maximum size of selected files (kb).
type1 | type2 .. : Mime types allowed.

Validate files based on the javascript file API (if not available, validation is not performed), setting the minimum and maximum of selected files where maximum can be omitted (*), the maximum and minimum size in kb. For each file where both can be omitted (*) and finally validate the file type following the mime types specified as array (at least one is required).

data-dj-validator="file,2,4,10,100,
image/jpeg|image/png|image/bmp"
data-dj-validator="file,1,*,1,1000,image/jpeg"
data-dj-validator="file,1,3,*,*,image/jpeg|image/png"

Validate file extensions

efile, [e1 | e2 | e3 ..]

e1 | e2 | e3 .. : File extensions allowed

Validate only the file extension of the selected file within the list of allowed extensions (at least one is required), it can be used more easily and when javascript file API is not available.

data-dj-validator="efile,jpg|jpeg|png|bmp"
data-dj-validator="efile,doc|docx|pdf"

Validation of other form controls

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Select multiple

multi, [min], [max]

min: minimum of selected options.
max : maximum of selected options.

Validate the number of options selected from a multiple select, the maximum can be omitted (*).

The required attribute is valid to verify that an option with value has been selected.

data-dj-validator="multi,2,4"
data-dj-validator="multi,1,*"

Radio buttons

radio

NONE

Validate the required selection of a radio button of a group (with the same name), must be placed only a one radio of group (recommended in the last)

data-dj-validator="radio"

Checkbox

check, [group], [min], [max], [label]

group (optional): Name of the group of checkbox (attribute data-dj-validator-group).
min (optional): minimum of checked checkbox of the group.
max (optional): maximum of checked checkbox of the group.
label (optional):
checkbox group label.

Without parameters it validates that the checkbox is checked (required).
Specifying all parameters validates checking of a defined group of checkbox (all checks with the same data-dj-validator-group attribute), the maximum of options can be omitted (*), the [label] parameter is the group name label for validation message.

data-dj-validator="check"
data-dj-validator="check,group,1,2,options"
data-dj-validator="check,group,2,*,options"

Validate related fields

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Equal fields

equal, [id], [label]

id : id of the input to compare.
Label : Display label.

Validate that the value of field is equal to that specified, the [id] must be of field with which you want to compare.

The tag is used to label the other field.
data-dj-validator="equal,a,input a"
where "a" is the other field "id"

Different fields

nequal, [id], [label]

id : id of the input to compare.
Label : Display label

Validate that the value of the field is different from the specified, the [id] must be of field with which you want to compare.

The tag is used to label the other field.
data-dj-validator="nequal,a,input a"
where "a" is the other field "id"

Optional fields

or, [group], [label]

group : Name of group (fields with the same data-dj-validator-group attribute).
Label : Display label

Validate that at least one field of the group is not empty (required group), the [label] parameter is the label of the group to display message.
The "or" validator must be placed in a only field of group(recommended in the last)

data-dj-validator="or,optionals,optional inputs"
where each input group is: data-dj-validator-group = "optionals"

Custom validations

VALIDATION

KEY

PARAMETERS

DESCRIPTION

EXAMPLES

Validate a regular expression

regexp, [regular_expresion], [flags]

regular_expresion : regular expression to use.
Flags (optional): flags of the regular expression.

Accept field value according to specified regular expression and flags(specified separately), must be in string format (for use with the RegExp object constructor).
If the regular expression has commas (reserved operator), they must be replaced by the character: ° , to avoid errors.

data-dj-validator="regexp,^[aeiou]+$,i"
data-dj-validator="regexp,^[aeiou]{3°5}$,i"

Call an own validation function

call, [function_name]

function_name : name of the validating function.

Call a user function to perform the validation, this user function receives the field to be validated ($obj) and must return true or false.

data-dj-validator="call,isUpperCase"
where "isUpperCase" is the user's function
Check the custom validations section for more details.

Server validation

Check server validation section.