class-property
flagrate.Form.inputValidator
flagrate.Form.inputValidator → Object
Built-in validators
- numeric
- alphanumeric
Basic validator
// success and error messages are optional
{ regexp: /RegExp/, success: 'String', error: 'String' }
// warning state is not available in this way, see Advanced.
Advanced validator
// Sync or Async validation
function (input, done) { done(result, message); }// message is optional
// Examples
function (input, done) { done(true); }// success
function (input, done) { done(null); }// warning
function (input, done) { done(false); }// error
function (input, done) { done('success'); }// success
function (input, done) { done('warning'); }// warning
function (input, done) { done('error'); }// error
function (input, done) { done(true, '...'); }// success with message
function (input, done) { done(null, '...'); }// warning with message
function (input, done) { done(false, '...'); }// error with message
Example: adding error message to built-in validators
flagrate.Form.inputValidator.numeric.error = 'Please enter a numbers.';
flagrate.Form.inputValidator.alphanumeric.error = 'Please enter a alphanumeric.';
Example: add the custom validator to Flagrate (to create plugin)
flagrate.Form.inputValidator.hostname = {
regexp: /^[a-z0-9]+(-[a-z0-9]+)*(\.([a-z0-9]+(-[a-z0-9]+)*))*$/i,
error: 'Please enter a valid hostname string.'
};