Options
domain(value)
Use this function to test if the given value or the input is a domain.
Code examples
Initialize the validator with the domain option specified, using object in constructor
//The validator will check automatically if the input's value is a domain
$A.newInput().validator({
domain:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().domain('this is not a domain!'); //will return false
$('body').text('domain: '+result);
domainOrUrl(value)
Use this option to test if the given value or the input is a domain or an url.
Code examples
Initialize the validator with the domainOrUrl option specified, using object in constructor
$A.newInput().validator({
domainOrUrl:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().domainOrUrl('this is not a domain or url!'); //will return false
$('body').text('domain or url: '+result);
email(value)
Use this option to test if the given value or the input is an email address.
Code examples
Initialize the validator with the email option specified, using object in constructor
$A.newInput().validator({
email:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().email('this is not an email address!'); //will return false
$('body').text('email: '+result);
integer(value)
Use this option to test if the given value or the input is an integer.
Code examples
Initialize the validator with the integer option specified, using object in constructor
$A.newInput().validator({
integer:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().integer('this is not an integer!'); //will return false
$('body').text('integer: '+result);
invalidValue(value, invalidValue)
Use this option to test if the given value or the input equals to a predefined invalid value.
Code examples
Initialize the validator with the invalidValue option specified, using object in constructor
//invalid@invalid.com meets the email pattern, but it won't be accepted
$A.newInput().validator({
email:true,
invalidValue: 'invalid@invalid.com'
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().invalidValue('invalid@invalid.com','invalid@invalid.com'); //will return false
$('body').text('valid email: '+result);
max(value, maxValue)
Use this option to test if the given value or the input is lower then a maximum value.
Code examples
Initialize the validator with the max option specified, using object in constructor
$A.newInput().validator({
max:100
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().max(101, 100); //will return false
$('body').text('lower or equal to max: '+result);
maxLength(value, maxLenght)
Use this option to test if the given value or the input is longer than a maximum length.
Code examples
Initialize the validator with the maxLength option specified, using object in constructor
$A.newInput().validator({
maxLength:5
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().maxLength('this is longer than 5', 5); //will return false
$('body').text('not too long: '+result);
min(value, minValue)
Use this option to test if the given value or the input is lower than a minimum value.
Code examples
Initialize the validator with the min option specified, using object in constructor
$A.newInput().validator({
min:4
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().min('low', 4); //will return false
$('body').text('high enough: '+result);
minLength
Use this option to test if the given value or the input is shorter than a minimum length.
Code examples
Initialize the validator with the minLength option specified, using object in constructor
$A.newInput().validator({
minLength:6
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().minLength('short',6); //will return false
$('body').text('long enough: '+result);
notEmpty(value)
Use this option to test if the given value or the input is empty.
Code examples
Initialize the validator with the notEmpty option specified, using object in constructor
$A.newInput().validator({
notEmpty:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().notEmpty(''); //will return false
$('body').text('not empty: '+result);
number(value)
Use this option to test if the given value or the input is a number.
Code examples
Initialize the validator with the number option specified, using object in constructor
$A.newInput().validator({
number:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().number('not number'); //will return false
$('body').text('number: '+result);
url
Use this option to test if the given value or the input is a url,
Code examples
Initialize the validator with the url option specified, using object in constructor
$A.newInput().validator({
url:true
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var result = $A.newValidator().url('this is not an url!'); //will return false
$('body').text('url: '+result);
value(val)
Use this option to set the value you want to test with the validator.
Pleas note that if you assign the validator to an input, the value attribute will be the value of the input, so there's basically no sense of changing it.
Code examples
Initialize the validator with the value option specified, using object in constructor
$A.newInput().validator({
value: 'some text'
}).draw();
Checking if the given input is valid or not
//Checking a value with a single validator
var validator = $A.newValidator({
email:true,
value: 'mail'
});
var result = validator.execute();
$('body').text('email: '+result);
Methods
errors
Use this method to get the array of error messages it produced.
Code examples
var validator = $A.newValidator();
validator.email('mail');
$('body').text('errors: '+validator.errors());
execute
Use this method to execute the validation process. (It calls the run method and returns its result.)
Please note, that if the validator is assigned to an input, the function execute will be invoked automatically on any change of the input.
Code examples
var validator = $A.newValidator({
email: true,
value: 'mail'
});
$('body').text('result: '+validator.execute());
run
Use this method to evaluate all attributes.
Code examples
$A.newValidator({
email:true,
minLength:4,
value: 'mail'
}).run();
sameas(value, otherValue)
Use this method to check if two values are equal.
Code examples
var result = $A.newValidator().sameas('value','value2') //will return false;
$('body').text('two values are equal: '+result);