miércoles, 12 de abril de 2017

Validators reference

Validations available:

DjValidator has by default the following validation keys, which must be placed as Strings within the data-dj-validator attribute, except for validating a required field that recognizes the required HTML5 attribute.


Validation
key
Parameters
Description
Required field
Use the "required" HTML5 attribute
-----
The field must not be empty or contain only spaces, it is obligatory.

Any text
text, [min],[max]
min: minimum of allowed characters.

max: maximum of allowed characters.
Accepts any character by validating only the length of the text. Maximum size can be omitted (*).
Alphabetic text
atext, [min],[max]
min: minimum of allowed characters.

max: maximum of allowed characters.
Accepts uppercase and lowercase alphabetic characters, including spaces, the letter ñ and the accented characters (á, é, í, ó, ú, ç, ü) by validating the length of the text. Maximum size can be omitted (*).

Alphabetic text and digits
antext, [min],[max]
min: minimum of allowed characters.

max: maximum of allowed characters.
Accepts digits and alphabetic characters in uppercase and lowercase letters, including spaces, letter ñ and accented characters (á, é, í, ó, ú, ç, ü) by validating the length of the text. Maximum size can be omitted (*).

A word (text without spaces)
word, [min],[max]
min: minimum of allowed characters.

max: maximum of allowed characters.
Accept any character except the spaces, validating the length of the text. Maximum size can be omitted (*).
Only digits
dig, [min],[max]
min: minimum of allowed digits.

max: maximum of allowed digits.
Accepts a single digit text, validating its length. Maximum size can be omitted (*).
Only integers
int, [min],[max]
min: minimum value allowed.

max: maximum value allowed.
Accept only positive or negative integers (accept the minus - sign), validating the integer value. The maximum and/or minimum value can be omitted (*).

Any real number
num, [min],[max]
min: minimum value allowed.

max: maximum value allowed.
Accepts any type of real number, using the period (.) as decimal separator, accepts the minus - sign, validating the value of the number. The maximum and/or minimum value can be omitted (*).

Email
email,[max]
max: maximum of allowed characters.
Accept valid email of any domain level, also validating the optional maximum size (*).

URL
url,[max]
max: maximum of allowed characters.
Accepts valid URLs of HTTP, HTTPS, FTP and FTPS protocols; also validating the optional maximum size (*).

Phone number
phone
Any.
Accepts telephone 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 must have 5 to 12 digits.

File validation
file,[min],[max],[min_size],[max_size],[type1|type2....]
min: minimum number of selected files.

max: maximum number of selected files.

min_size: minimum size of selected files.

max_size: maximum size of selected files.

type1|type2....: Allowed mime types.
Validates file-type inputs based on the javascript API (if not available, the validation is not available), setting the minimum and maximum of selected files where the maximum can be omitted (*), the maximum and minimum size in kb. of the selected files that can also be omitted (*) and finally validates the file type following the mime types specified as array (requires at least one).
File extension validation
efile,[e1|e2|e3….]
e1|e2|e3…: 
File extensions allowed.
Validate only the extension of the selected file within the list of allowed extensions (there must be at least one), it can be used more easily and when the javascript API file is not available.

IP adress
Ip,[type]
type(optional): v4 or v6
Accepts IP addresses that can be v4 or v6 depending on the specified parameter, if not specified v4 and v6 validated.

Select multiple
multi,[min],[max]
min: minimum of selected options.

max: maximum of selected options.
Validate the number of options selected from a select multiple, the maximum can be omitted (*).
Radio buttons
radio
Any.
Validates the required selection of a radio button from a group of radios (with the same name).

Checkboxes
check,[group],[min],[max],[label]
group (optional): Name of the group of boxs (attribute data-dj-validator-group).

min (optional): minimum checkboxes checked.

max (optional): maximum checkboxes checked.

Label (optional)
Name of the group of boxes for display.
Without parameters, validate that the box is selected (required).

Specifying all the parameters validates the marking of a defined group of boxes (attribute data-dj-validator-group), the maximum of options can be omitted (*), the parameter [label] is only to show the message.
Equal fields
equal,[id],[label]
id: id of the input to be compared.
Label: Name of inputs for display.
Validate that the value of the field is equal to that specified, [id] must be of the field (other) with which to compare.
Different fields
nequal,[id],[label]
id: id of the input to be compared.
Label: Name of inputs for display.
Validate that the value of the field is different from that specified, [id] must be of the field (other) with which to compare.

Optional fields
or,[group],[label]
group: Name of the field group (data-dj-validator-group attribute).

Label: Name of the group of inputs for display.
Validate that at least one of the fields in the group is not empty (required group), the parameter [label] is only to display the message.
Regular expressions
regexp,[ regular_expresion],[ flags]
regular_expresion: regular expression.
Flags(optional): flags of the regular expression.

Accepts the value of a field in accordance with the specified regular expression, the format of the expression and the flags (specified separately) must be as strings (to be used with the constructor of the RegExp object).
If the regular expression has commas, these must be replaced by: ° to avoid errors (v1.1.0).
Call own function
call,[function_name]
function_name: Name of the validating function.
Call a own function to perform validation, this own function receives the field to validate ($obj) and must return true or false.

No hay comentarios:

Publicar un comentario