formvalidation
Version:
The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit and custom frameworks
37 lines (34 loc) • 1.05 kB
JavaScript
/**
* digits validator
*
* @link http://formvalidation.io/validators/digits/
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
(function($) {
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
'en_US': {
digits: {
'default': 'Please enter only digits'
}
}
});
FormValidation.Validator.digits = {
/**
* Return true if the input value contains digits only
*
* @param {FormValidation.Base} validator Validate plugin instance
* @param {jQuery} $field Field element
* @param {Object} [options]
* @returns {Boolean}
*/
validate: function(validator, $field, options) {
var value = validator.getFieldValue($field, 'digits');
if (value === '') {
return true;
}
return /^\d+$/.test(value);
}
};
}(jQuery));