Files
OnlineJudge/static/src/js/lib/formValidation/validator/digits.js
2015-08-02 12:21:12 +08:00

53 lines
1.4 KiB
JavaScript
Executable File

/**
* 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(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("validator/digits", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
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);
}
};
return FormValidation.Validator.digits;
}));