54 lines
1.5 KiB
JavaScript
Executable File
54 lines
1.5 KiB
JavaScript
Executable File
/**
|
|
* hex validator
|
|
*
|
|
* @link http://formvalidation.io/validators/hex/
|
|
* @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/hex", ["jquery", "base"], factory);
|
|
} else {
|
|
// planted over the root!
|
|
factory(root.jQuery, root.FormValidation);
|
|
}
|
|
|
|
}(this, function ($, FormValidation) {
|
|
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
|
'en_US': {
|
|
hex: {
|
|
'default': 'Please enter a valid hexadecimal number'
|
|
}
|
|
}
|
|
});
|
|
|
|
FormValidation.Validator.hex = {
|
|
/**
|
|
* Return true if and only if the input value is a valid hexadecimal number
|
|
*
|
|
* @param {FormValidation.Base} validator The validator plugin instance
|
|
* @param {jQuery} $field Field element
|
|
* @param {Object} options Consist of key:
|
|
* - message: The invalid message
|
|
* @returns {Boolean}
|
|
*/
|
|
validate: function(validator, $field, options) {
|
|
var value = validator.getFieldValue($field, 'hex');
|
|
if (value === '') {
|
|
return true;
|
|
}
|
|
|
|
return /^[0-9a-fA-F]+$/.test(value);
|
|
}
|
|
};
|
|
|
|
|
|
return FormValidation.Validator.hex;
|
|
}));
|