自动排除了 lib,导致js 不全
This commit is contained in:
72
static/src/js/lib/formValidation/validator/imei.js
Executable file
72
static/src/js/lib/formValidation/validator/imei.js
Executable file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* imei validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/imei/
|
||||
* @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/imei", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
imei: {
|
||||
'default': 'Please enter a valid IMEI number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.imei = {
|
||||
/**
|
||||
* Validate IMEI (International Mobile Station Equipment Identity)
|
||||
* Examples:
|
||||
* - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
|
||||
* - Invalid: 490154203237517
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'imei');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case /^\d{15}$/.test(value):
|
||||
case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
|
||||
case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
|
||||
value = value.replace(/[^0-9]/g, '');
|
||||
return FormValidation.Helper.luhn(value);
|
||||
|
||||
case /^\d{14}$/.test(value):
|
||||
case /^\d{16}$/.test(value):
|
||||
case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
|
||||
case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.imei;
|
||||
}));
|
||||
Reference in New Issue
Block a user