Grab the <input /> tag from the DOM tree and start the data validation
Documentation
Configuration object
Validator.init function accepts consfiguration object like this one:
These are minimum set of values. Additionally you can pass in messages and regExps objects to replace predefined settings or add your own testing rules:
Basic validation
Generally, you want the validation to occur with certain events (e.g. click, keyup, etc.). In this case consider this code:
Validation methods
required
Validator.fn.required returns if the value contains at least one symbol, except for whitespace
min
Validator.fn.min returns if the value length is more than provided length
max
Validator.fn.max returns if the value length is less than provided length
match
Validator.fn.match returns if the value matches certain pattern. Available patterns:
email
url
numbers
digits
letters
You can also define tou regular expression in config object and then use it:
Callbacks
onError
onError callback, which you define in config object, will be called every time Validator.fn.validate method fails:
onSuccess
onSuccess callback, which you define in config object, will be called every time Validator.fn.validate method passed:
Creating messages
You can create your own messages with simple template variables %rule% and %data%:
%data% refers to the current value from input field. %rule% refers to current param (e.g. 8 at min, 50 at max and email at match).