自动排除了 lib,导致js 不全
This commit is contained in:
52
static/src/js/lib/formValidation/validator/base64.js
Executable file
52
static/src/js/lib/formValidation/validator/base64.js
Executable file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* base64 validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/base64/
|
||||
* @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/XXXXXXXXXXXXXXXXXXXXXXXXXbase64", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
base64: {
|
||||
'default': 'Please enter a valid base 64 encoded'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.base64 = {
|
||||
/**
|
||||
* Return true if the input value is a base 64 encoded string.
|
||||
*
|
||||
* @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, 'base64');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
return FormValidation.Validator.base64;
|
||||
}));
|
||||
105
static/src/js/lib/formValidation/validator/between.js
Executable file
105
static/src/js/lib/formValidation/validator/between.js
Executable file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* between validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/between/
|
||||
* @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/between", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
between: {
|
||||
'default': 'Please enter a value between %s and %s',
|
||||
notInclusive: 'Please enter a value between %s and %s strictly'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.between = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
min: 'min',
|
||||
max: 'max',
|
||||
inclusive: 'inclusive'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
if ('range' === $field.attr('type')) {
|
||||
return {
|
||||
min: $field.attr('min'),
|
||||
max: $field.attr('max')
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is between (strictly or not) two given numbers
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - min
|
||||
* - max
|
||||
*
|
||||
* The min, max keys define the number which the field value compares to. min, max can be
|
||||
* - A number
|
||||
* - Name of field which its value defines the number
|
||||
* - Name of callback function that returns the number
|
||||
* - A callback function that returns the number
|
||||
*
|
||||
* - inclusive [optional]: Can be true or false. Default is true
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'between');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = this._format(value);
|
||||
if (!$.isNumeric(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
|
||||
max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
|
||||
minValue = this._format(min),
|
||||
maxValue = this._format(max);
|
||||
|
||||
value = parseFloat(value);
|
||||
return (options.inclusive === true || options.inclusive === undefined)
|
||||
? {
|
||||
valid: value >= minValue && value <= maxValue,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].between['default'], [min, max])
|
||||
}
|
||||
: {
|
||||
valid: value > minValue && value < maxValue,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].between.notInclusive, [min, max])
|
||||
};
|
||||
},
|
||||
|
||||
_format: function(value) {
|
||||
return (value + '').replace(',', '.');
|
||||
}
|
||||
};
|
||||
|
||||
return FormValidation.Validator.between;
|
||||
}));
|
||||
55
static/src/js/lib/formValidation/validator/bic.js
Executable file
55
static/src/js/lib/formValidation/validator/bic.js
Executable file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* bic validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/bic/
|
||||
* @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/bic", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
bic: {
|
||||
'default': 'Please enter a valid BIC number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.bic = {
|
||||
/**
|
||||
* Validate an Business Identifier Code (BIC), also known as ISO 9362, SWIFT-BIC, SWIFT ID or SWIFT code
|
||||
*
|
||||
* For more information see http://en.wikipedia.org/wiki/ISO_9362
|
||||
*
|
||||
* @todo The 5 and 6 characters are an ISO 3166-1 country code, this could also be validated
|
||||
* @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 {Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'bic');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
return /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.bic;
|
||||
}));
|
||||
52
static/src/js/lib/formValidation/validator/blank.js
Executable file
52
static/src/js/lib/formValidation/validator/blank.js
Executable file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* blank validator
|
||||
*
|
||||
* @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/blank", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.Validator.blank = {
|
||||
/**
|
||||
* Placeholder validator that can be used to display a custom validation message
|
||||
* returned from the server
|
||||
* Example:
|
||||
*
|
||||
* (1) a "blank" validator is applied to an input field.
|
||||
* (2) data is entered via the UI that is unable to be validated client-side.
|
||||
* (3) server returns a 400 with JSON data that contains the field that failed
|
||||
* validation and an associated message.
|
||||
* (4) ajax 400 call handler does the following:
|
||||
*
|
||||
* bv.updateMessage(field, 'blank', errorMessage);
|
||||
* bv.updateStatus(field, 'INVALID');
|
||||
*
|
||||
* @see https://github.com/formvalidation/formvalidation/issues/542
|
||||
* @see https://github.com/formvalidation/formvalidation/pull/666
|
||||
* @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) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.blank;
|
||||
}));
|
||||
69
static/src/js/lib/formValidation/validator/callback.js
Executable file
69
static/src/js/lib/formValidation/validator/callback.js
Executable file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* callback validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/callback/
|
||||
* @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/callback", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
callback: {
|
||||
'default': 'Please enter a valid value'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.callback = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
callback: 'callback'
|
||||
},
|
||||
|
||||
/**
|
||||
* Return result from the callback method
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - callback: The callback method that passes 2 parameters:
|
||||
* callback: function(fieldValue, validator, $field) {
|
||||
* // fieldValue is the value of field
|
||||
* // validator is instance of BootstrapValidator
|
||||
* // $field is the field element
|
||||
* }
|
||||
* - message: The invalid message
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'callback'),
|
||||
dfd = new $.Deferred(),
|
||||
result = { valid: true };
|
||||
|
||||
if (options.callback) {
|
||||
var response = FormValidation.Helper.call(options.callback, [value, validator, $field]);
|
||||
result = ('boolean' === typeof response) ? { valid: response } : response;
|
||||
}
|
||||
|
||||
dfd.resolve($field, 'callback', result);
|
||||
return dfd;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.callback;
|
||||
}));
|
||||
97
static/src/js/lib/formValidation/validator/choice.js
Executable file
97
static/src/js/lib/formValidation/validator/choice.js
Executable file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* choice validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/choice/
|
||||
* @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/choice", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
choice: {
|
||||
'default': 'Please enter a valid value',
|
||||
less: 'Please choose %s options at minimum',
|
||||
more: 'Please choose %s options at maximum',
|
||||
between: 'Please choose %s - %s options'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.choice = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
min: 'min',
|
||||
max: 'max'
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the number of checked boxes are less or more than a given number
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of following keys:
|
||||
* - min
|
||||
* - max
|
||||
*
|
||||
* At least one of two keys is required
|
||||
* The min, max keys define the number which the field value compares to. min, max can be
|
||||
* - A number
|
||||
* - Name of field which its value defines the number
|
||||
* - Name of callback function that returns the number
|
||||
* - A callback function that returns the number
|
||||
*
|
||||
* - message: The invalid message
|
||||
* @returns {Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var locale = validator.getLocale(),
|
||||
ns = validator.getNamespace(),
|
||||
numChoices = $field.is('select')
|
||||
? validator.getFieldElements($field.attr('data-' + ns + '-field')).find('option').filter(':selected').length
|
||||
: validator.getFieldElements($field.attr('data-' + ns + '-field')).filter(':checked').length,
|
||||
min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
|
||||
max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
|
||||
isValid = true,
|
||||
message = options.message || FormValidation.I18n[locale].choice['default'];
|
||||
|
||||
if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case (!!min && !!max):
|
||||
message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.between, [parseInt(min, 10), parseInt(max, 10)]);
|
||||
break;
|
||||
|
||||
case (!!min):
|
||||
message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.less, parseInt(min, 10));
|
||||
break;
|
||||
|
||||
case (!!max):
|
||||
message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.more, parseInt(max, 10));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return { valid: isValid, message: message };
|
||||
}
|
||||
};
|
||||
|
||||
return FormValidation.Validator.choice;
|
||||
}));
|
||||
172
static/src/js/lib/formValidation/validator/color.js
Executable file
172
static/src/js/lib/formValidation/validator/color.js
Executable file
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* color validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/color/
|
||||
* @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/color", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
color: {
|
||||
'default': 'Please enter a valid color'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.color = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
type: 'type'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
return ('color' === $field.attr('type'));
|
||||
},
|
||||
|
||||
SUPPORTED_TYPES: [
|
||||
'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'keyword'
|
||||
],
|
||||
|
||||
KEYWORD_COLORS: [
|
||||
// Colors start with A
|
||||
'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
|
||||
// B
|
||||
'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood',
|
||||
// C
|
||||
'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan',
|
||||
// D
|
||||
'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta',
|
||||
'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue',
|
||||
'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray',
|
||||
'dimgrey', 'dodgerblue',
|
||||
// F
|
||||
'firebrick', 'floralwhite', 'forestgreen', 'fuchsia',
|
||||
// G
|
||||
'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey',
|
||||
// H
|
||||
'honeydew', 'hotpink',
|
||||
// I
|
||||
'indianred', 'indigo', 'ivory',
|
||||
// K
|
||||
'khaki',
|
||||
// L
|
||||
'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
|
||||
'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
|
||||
'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen',
|
||||
'linen',
|
||||
// M
|
||||
'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen',
|
||||
'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream',
|
||||
'mistyrose', 'moccasin',
|
||||
// N
|
||||
'navajowhite', 'navy',
|
||||
// O
|
||||
'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid',
|
||||
// P
|
||||
'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink',
|
||||
'plum', 'powderblue', 'purple',
|
||||
// R
|
||||
'red', 'rosybrown', 'royalblue',
|
||||
// S
|
||||
'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
|
||||
'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue',
|
||||
// T
|
||||
'tan', 'teal', 'thistle', 'tomato', 'transparent', 'turquoise',
|
||||
// V
|
||||
'violet',
|
||||
// W
|
||||
'wheat', 'white', 'whitesmoke',
|
||||
// Y
|
||||
'yellow', 'yellowgreen'
|
||||
],
|
||||
|
||||
/**
|
||||
* Return true if the input value is a valid color
|
||||
*
|
||||
* @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
|
||||
* - type: The array of valid color types
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'color');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only accept 6 hex character values due to the HTML 5 spec
|
||||
// See http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
|
||||
if (this.enableByHtml5($field)) {
|
||||
return /^#[0-9A-F]{6}$/i.test(value);
|
||||
}
|
||||
|
||||
var types = options.type || this.SUPPORTED_TYPES;
|
||||
if (!$.isArray(types)) {
|
||||
types = types.replace(/s/g, '').split(',');
|
||||
}
|
||||
|
||||
var method,
|
||||
type,
|
||||
isValid = false;
|
||||
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
type = types[i];
|
||||
method = '_' + type.toLowerCase();
|
||||
isValid = isValid || this[method](value);
|
||||
if (isValid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
_hex: function(value) {
|
||||
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
|
||||
},
|
||||
|
||||
_hsl: function(value) {
|
||||
return /^hsl\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/.test(value);
|
||||
},
|
||||
|
||||
_hsla: function(value) {
|
||||
return /^hsla\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/.test(value);
|
||||
},
|
||||
|
||||
_keyword: function(value) {
|
||||
return $.inArray(value, this.KEYWORD_COLORS) >= 0;
|
||||
},
|
||||
|
||||
_rgb: function(value) {
|
||||
var regexInteger = /^rgb\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){2}(\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*)\)$/,
|
||||
regexPercent = /^rgb\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/;
|
||||
return regexInteger.test(value) || regexPercent.test(value);
|
||||
},
|
||||
|
||||
_rgba: function(value) {
|
||||
var regexInteger = /^rgba\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/,
|
||||
regexPercent = /^rgba\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/;
|
||||
return regexInteger.test(value) || regexPercent.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.color;
|
||||
}));
|
||||
134
static/src/js/lib/formValidation/validator/creditCard.js
Executable file
134
static/src/js/lib/formValidation/validator/creditCard.js
Executable file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* creditCard validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/creditCard/
|
||||
* @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/creditCard", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
creditCard: {
|
||||
'default': 'Please enter a valid credit card number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.creditCard = {
|
||||
/**
|
||||
* Return true if the input value is valid credit card number
|
||||
* Based on https://gist.github.com/DiegoSalazar/4075533
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} [options] Can consist of the following key:
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'creditCard');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Accept only digits, dashes or spaces
|
||||
if (/[^0-9-\s]+/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
value = value.replace(/\D/g, '');
|
||||
|
||||
if (!FormValidation.Helper.luhn(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the card number based on prefix (IIN ranges) and length
|
||||
var cards = {
|
||||
AMERICAN_EXPRESS: {
|
||||
length: [15],
|
||||
prefix: ['34', '37']
|
||||
},
|
||||
DINERS_CLUB: {
|
||||
length: [14],
|
||||
prefix: ['300', '301', '302', '303', '304', '305', '36']
|
||||
},
|
||||
DINERS_CLUB_US: {
|
||||
length: [16],
|
||||
prefix: ['54', '55']
|
||||
},
|
||||
DISCOVER: {
|
||||
length: [16],
|
||||
prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
|
||||
'62214', '62215', '62216', '62217', '62218', '62219',
|
||||
'6222', '6223', '6224', '6225', '6226', '6227', '6228',
|
||||
'62290', '62291', '622920', '622921', '622922', '622923',
|
||||
'622924', '622925', '644', '645', '646', '647', '648',
|
||||
'649', '65']
|
||||
},
|
||||
JCB: {
|
||||
length: [16],
|
||||
prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
|
||||
},
|
||||
LASER: {
|
||||
length: [16, 17, 18, 19],
|
||||
prefix: ['6304', '6706', '6771', '6709']
|
||||
},
|
||||
MAESTRO: {
|
||||
length: [12, 13, 14, 15, 16, 17, 18, 19],
|
||||
prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
|
||||
},
|
||||
MASTERCARD: {
|
||||
length: [16],
|
||||
prefix: ['51', '52', '53', '54', '55']
|
||||
},
|
||||
SOLO: {
|
||||
length: [16, 18, 19],
|
||||
prefix: ['6334', '6767']
|
||||
},
|
||||
UNIONPAY: {
|
||||
length: [16, 17, 18, 19],
|
||||
prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
|
||||
'62215', '62216', '62217', '62218', '62219', '6222', '6223',
|
||||
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
|
||||
'622920', '622921', '622922', '622923', '622924', '622925']
|
||||
},
|
||||
VISA: {
|
||||
length: [16],
|
||||
prefix: ['4']
|
||||
}
|
||||
};
|
||||
|
||||
var type, i;
|
||||
for (type in cards) {
|
||||
for (i in cards[type].prefix) {
|
||||
if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
|
||||
&& $.inArray(value.length, cards[type].length) !== -1) // and length
|
||||
{
|
||||
return {
|
||||
valid: true,
|
||||
type: type
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.creditCard;
|
||||
}));
|
||||
83
static/src/js/lib/formValidation/validator/cusip.js
Executable file
83
static/src/js/lib/formValidation/validator/cusip.js
Executable file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* cusip validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/cusip/
|
||||
* @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/cusip", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
cusip: {
|
||||
'default': 'Please enter a valid CUSIP number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.cusip = {
|
||||
/**
|
||||
* Validate a CUSIP number
|
||||
* Examples:
|
||||
* - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
|
||||
* - Invalid: 31430F200, 022615AC2
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/CUSIP
|
||||
* @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, 'cusip');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = value.toUpperCase();
|
||||
if (!/^[0-9A-Z]{9}$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var converted = $.map(value.split(''), function(item) {
|
||||
var code = item.charCodeAt(0);
|
||||
return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
|
||||
// Replace A, B, C, ..., Z with 10, 11, ..., 35
|
||||
? (code - 'A'.charCodeAt(0) + 10)
|
||||
: item;
|
||||
}),
|
||||
length = converted.length,
|
||||
sum = 0;
|
||||
for (var i = 0; i < length - 1; i++) {
|
||||
var num = parseInt(converted[i], 10);
|
||||
if (i % 2 !== 0) {
|
||||
num *= 2;
|
||||
}
|
||||
if (num > 9) {
|
||||
num -= 9;
|
||||
}
|
||||
sum += num;
|
||||
}
|
||||
|
||||
sum = (10 - (sum % 10)) % 10;
|
||||
return sum === parseInt(converted[length - 1], 10);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.cusip;
|
||||
}));
|
||||
179
static/src/js/lib/formValidation/validator/cvv.js
Executable file
179
static/src/js/lib/formValidation/validator/cvv.js
Executable file
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* cvv validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/cvv/
|
||||
* @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/cvv", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
cvv: {
|
||||
'default': 'Please enter a valid CVV number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.cvv = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
ccfield: 'creditCardField'
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind the validator on the live change of the credit card field
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - creditCardField: The credit card number field
|
||||
*/
|
||||
init: function(validator, $field, options) {
|
||||
if (options.creditCardField) {
|
||||
var creditCardField = validator.getFieldElements(options.creditCardField);
|
||||
validator.onLiveChange(creditCardField, 'live_cvv', function() {
|
||||
var status = validator.getStatus($field, 'cvv');
|
||||
if (status !== validator.STATUS_NOT_VALIDATED) {
|
||||
validator.revalidateField($field);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Unbind the validator on the live change of the credit card field
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - creditCardField: The credit card number field
|
||||
*/
|
||||
destroy: function(validator, $field, options) {
|
||||
if (options.creditCardField) {
|
||||
var creditCardField = validator.getFieldElements(options.creditCardField);
|
||||
validator.offLiveChange(creditCardField, 'live_cvv');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is a valid CVV number.
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - creditCardField: The credit card number field. It can be null
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'cvv');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!/^[0-9]{3,4}$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!options.creditCardField) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the credit card number
|
||||
var creditCard = validator.getFieldElements(options.creditCardField).val();
|
||||
if (creditCard === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
creditCard = creditCard.replace(/\D/g, '');
|
||||
|
||||
// Supported credit card types
|
||||
var cards = {
|
||||
AMERICAN_EXPRESS: {
|
||||
length: [15],
|
||||
prefix: ['34', '37']
|
||||
},
|
||||
DINERS_CLUB: {
|
||||
length: [14],
|
||||
prefix: ['300', '301', '302', '303', '304', '305', '36']
|
||||
},
|
||||
DINERS_CLUB_US: {
|
||||
length: [16],
|
||||
prefix: ['54', '55']
|
||||
},
|
||||
DISCOVER: {
|
||||
length: [16],
|
||||
prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
|
||||
'62214', '62215', '62216', '62217', '62218', '62219',
|
||||
'6222', '6223', '6224', '6225', '6226', '6227', '6228',
|
||||
'62290', '62291', '622920', '622921', '622922', '622923',
|
||||
'622924', '622925', '644', '645', '646', '647', '648',
|
||||
'649', '65']
|
||||
},
|
||||
JCB: {
|
||||
length: [16],
|
||||
prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
|
||||
},
|
||||
LASER: {
|
||||
length: [16, 17, 18, 19],
|
||||
prefix: ['6304', '6706', '6771', '6709']
|
||||
},
|
||||
MAESTRO: {
|
||||
length: [12, 13, 14, 15, 16, 17, 18, 19],
|
||||
prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
|
||||
},
|
||||
MASTERCARD: {
|
||||
length: [16],
|
||||
prefix: ['51', '52', '53', '54', '55']
|
||||
},
|
||||
SOLO: {
|
||||
length: [16, 18, 19],
|
||||
prefix: ['6334', '6767']
|
||||
},
|
||||
UNIONPAY: {
|
||||
length: [16, 17, 18, 19],
|
||||
prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
|
||||
'62215', '62216', '62217', '62218', '62219', '6222', '6223',
|
||||
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
|
||||
'622920', '622921', '622922', '622923', '622924', '622925']
|
||||
},
|
||||
VISA: {
|
||||
length: [16],
|
||||
prefix: ['4']
|
||||
}
|
||||
};
|
||||
var type, i, creditCardType = null;
|
||||
for (type in cards) {
|
||||
for (i in cards[type].prefix) {
|
||||
if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
|
||||
&& $.inArray(creditCard.length, cards[type].length) !== -1) // and length
|
||||
{
|
||||
creditCardType = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (creditCardType === null)
|
||||
? false
|
||||
: (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.cvv;
|
||||
}));
|
||||
381
static/src/js/lib/formValidation/validator/date.js
Executable file
381
static/src/js/lib/formValidation/validator/date.js
Executable file
@@ -0,0 +1,381 @@
|
||||
/**
|
||||
* date validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/date/
|
||||
* @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/date", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
date: {
|
||||
'default': 'Please enter a valid date',
|
||||
min: 'Please enter a date after %s',
|
||||
max: 'Please enter a date before %s',
|
||||
range: 'Please enter a date in the range %s - %s'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.date = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
format: 'format',
|
||||
min: 'min',
|
||||
max: 'max',
|
||||
separator: 'separator'
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is valid date
|
||||
*
|
||||
* @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
|
||||
* - min: the minimum date
|
||||
* - max: the maximum date
|
||||
* - separator: Use to separate the date, month, and year.
|
||||
* By default, it is /
|
||||
* - format: The date format. Default is MM/DD/YYYY
|
||||
* The format can be:
|
||||
*
|
||||
* i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
|
||||
* ii) date and time:
|
||||
* The time can consist of h, m, s parts which are separated by :
|
||||
* ii) date, time and A (indicating AM or PM)
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'date');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
options.format = options.format || 'MM/DD/YYYY';
|
||||
|
||||
// #683: Force the format to YYYY-MM-DD as the default browser behaviour when using type="date" attribute
|
||||
if ($field.attr('type') === 'date') {
|
||||
options.format = 'YYYY-MM-DD';
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
message = options.message || FormValidation.I18n[locale].date['default'],
|
||||
formats = options.format.split(' '),
|
||||
dateFormat = formats[0],
|
||||
timeFormat = (formats.length > 1) ? formats[1] : null,
|
||||
amOrPm = (formats.length > 2) ? formats[2] : null,
|
||||
sections = value.split(' '),
|
||||
date = sections[0],
|
||||
time = (sections.length > 1) ? sections[1] : null;
|
||||
|
||||
if (formats.length !== sections.length) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
|
||||
// Determine the separator
|
||||
var separator = options.separator;
|
||||
if (!separator) {
|
||||
separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
|
||||
}
|
||||
if (separator === null || date.indexOf(separator) === -1) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
|
||||
// Determine the date
|
||||
date = date.split(separator);
|
||||
dateFormat = dateFormat.split(separator);
|
||||
if (date.length !== dateFormat.length) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
|
||||
var year = date[$.inArray('YYYY', dateFormat)],
|
||||
month = date[$.inArray('MM', dateFormat)],
|
||||
day = date[$.inArray('DD', dateFormat)];
|
||||
|
||||
if (!year || !month || !day || year.length !== 4) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
|
||||
// Determine the time
|
||||
var minutes = null, hours = null, seconds = null;
|
||||
if (timeFormat) {
|
||||
timeFormat = timeFormat.split(':');
|
||||
time = time.split(':');
|
||||
|
||||
if (timeFormat.length !== time.length) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
|
||||
hours = time.length > 0 ? time[0] : null;
|
||||
minutes = time.length > 1 ? time[1] : null;
|
||||
seconds = time.length > 2 ? time[2] : null;
|
||||
|
||||
if (hours === '' || minutes === '' || seconds === '') {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
|
||||
// Validate seconds
|
||||
if (seconds) {
|
||||
if (isNaN(seconds) || seconds.length > 2) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
seconds = parseInt(seconds, 10);
|
||||
if (seconds < 0 || seconds > 60) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Validate hours
|
||||
if (hours) {
|
||||
if (isNaN(hours) || hours.length > 2) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
hours = parseInt(hours, 10);
|
||||
if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Validate minutes
|
||||
if (minutes) {
|
||||
if (isNaN(minutes) || minutes.length > 2) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
minutes = parseInt(minutes, 10);
|
||||
if (minutes < 0 || minutes > 59) {
|
||||
return {
|
||||
valid: false,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate day, month, and year
|
||||
var valid = FormValidation.Helper.date(year, month, day),
|
||||
// declare the date, min and max objects
|
||||
min = null,
|
||||
max = null,
|
||||
minOption = options.min,
|
||||
maxOption = options.max;
|
||||
|
||||
if (minOption) {
|
||||
if (isNaN(Date.parse(minOption))) {
|
||||
minOption = validator.getDynamicOption($field, minOption);
|
||||
}
|
||||
|
||||
min = minOption instanceof Date ? minOption : this._parseDate(minOption, dateFormat, separator);
|
||||
// In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)"
|
||||
minOption = minOption instanceof Date ? this._formatDate(minOption, options.format) : minOption;
|
||||
}
|
||||
|
||||
if (maxOption) {
|
||||
if (isNaN(Date.parse(maxOption))) {
|
||||
maxOption = validator.getDynamicOption($field, maxOption);
|
||||
}
|
||||
|
||||
max = maxOption instanceof Date ? maxOption : this._parseDate(maxOption, dateFormat, separator);
|
||||
// In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)"
|
||||
maxOption = maxOption instanceof Date ? this._formatDate(maxOption, options.format) : maxOption;
|
||||
}
|
||||
|
||||
date = new Date(year, month -1, day, hours, minutes, seconds);
|
||||
|
||||
switch (true) {
|
||||
case (minOption && !maxOption && valid):
|
||||
valid = date.getTime() >= min.getTime();
|
||||
message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.min, minOption);
|
||||
break;
|
||||
|
||||
case (maxOption && !minOption && valid):
|
||||
valid = date.getTime() <= max.getTime();
|
||||
message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.max, maxOption);
|
||||
break;
|
||||
|
||||
case (maxOption && minOption && valid):
|
||||
valid = date.getTime() <= max.getTime() && date.getTime() >= min.getTime();
|
||||
message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.range, [minOption, maxOption]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
valid: valid,
|
||||
message: message
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a date object after parsing the date string
|
||||
*
|
||||
* @param {String} date The date string to parse
|
||||
* @param {String} format The date format
|
||||
* The format can be:
|
||||
* - date: Consist of DD, MM, YYYY parts which are separated by the separator option
|
||||
* - date and time:
|
||||
* The time can consist of h, m, s parts which are separated by :
|
||||
* @param {String} separator The separator used to separate the date, month, and year
|
||||
* @returns {Date}
|
||||
*/
|
||||
_parseDate: function(date, format, separator) {
|
||||
var minutes = 0, hours = 0, seconds = 0,
|
||||
sections = date.split(' '),
|
||||
dateSection = sections[0],
|
||||
timeSection = (sections.length > 1) ? sections[1] : null;
|
||||
|
||||
dateSection = dateSection.split(separator);
|
||||
var year = dateSection[$.inArray('YYYY', format)],
|
||||
month = dateSection[$.inArray('MM', format)],
|
||||
day = dateSection[$.inArray('DD', format)];
|
||||
if (timeSection) {
|
||||
timeSection = timeSection.split(':');
|
||||
hours = timeSection.length > 0 ? timeSection[0] : null;
|
||||
minutes = timeSection.length > 1 ? timeSection[1] : null;
|
||||
seconds = timeSection.length > 2 ? timeSection[2] : null;
|
||||
}
|
||||
|
||||
return new Date(year, month -1, day, hours, minutes, seconds);
|
||||
},
|
||||
|
||||
/**
|
||||
* Format date
|
||||
*
|
||||
* @param {Date} date The date object to format
|
||||
* @param {String} format The date format
|
||||
* The format can consist of the following tokens:
|
||||
* d Day of the month without leading zeros (1 through 31)
|
||||
* dd Day of the month with leading zeros (01 through 31)
|
||||
* m Month without leading zeros (1 through 12)
|
||||
* mm Month with leading zeros (01 through 12)
|
||||
* yy Last two digits of year (for example: 14)
|
||||
* yyyy Full four digits of year (for example: 2014)
|
||||
* h Hours without leading zeros (1 through 12)
|
||||
* hh Hours with leading zeros (01 through 12)
|
||||
* H Hours without leading zeros (0 through 23)
|
||||
* HH Hours with leading zeros (00 through 23)
|
||||
* M Minutes without leading zeros (0 through 59)
|
||||
* MM Minutes with leading zeros (00 through 59)
|
||||
* s Seconds without leading zeros (0 through 59)
|
||||
* ss Seconds with leading zeros (00 through 59)
|
||||
* @returns {String}
|
||||
*/
|
||||
_formatDate: function(date, format) {
|
||||
format = format
|
||||
.replace(/Y/g, 'y')
|
||||
.replace(/M/g, 'm')
|
||||
.replace(/D/g, 'd')
|
||||
.replace(/:m/g, ':M')
|
||||
.replace(/:mm/g, ':MM')
|
||||
.replace(/:S/, ':s')
|
||||
.replace(/:SS/, ':ss');
|
||||
|
||||
var replacer = {
|
||||
d: function(date) {
|
||||
return date.getDate();
|
||||
},
|
||||
dd: function(date) {
|
||||
var d = date.getDate();
|
||||
return (d < 10) ? '0' + d : d;
|
||||
},
|
||||
m: function(date) {
|
||||
return date.getMonth() + 1;
|
||||
},
|
||||
mm: function(date) {
|
||||
var m = date.getMonth() + 1;
|
||||
return m < 10 ? '0' + m : m;
|
||||
},
|
||||
yy: function(date) {
|
||||
return ('' + date.getFullYear()).substr(2);
|
||||
},
|
||||
yyyy: function(date) {
|
||||
return date.getFullYear();
|
||||
},
|
||||
h: function(date) {
|
||||
return date.getHours() % 12 || 12;
|
||||
},
|
||||
hh: function(date) {
|
||||
var h = date.getHours() % 12 || 12;
|
||||
return h < 10 ? '0' + h : h;
|
||||
},
|
||||
H: function(date) {
|
||||
return date.getHours();
|
||||
},
|
||||
HH: function(date) {
|
||||
var H = date.getHours();
|
||||
return H < 10 ? '0' + H : H;
|
||||
},
|
||||
M: function(date) {
|
||||
return date.getMinutes();
|
||||
},
|
||||
MM: function(date) {
|
||||
var M = date.getMinutes();
|
||||
return M < 10 ? '0' + M : M;
|
||||
},
|
||||
s: function(date) {
|
||||
return date.getSeconds();
|
||||
},
|
||||
ss: function(date) {
|
||||
var s = date.getSeconds();
|
||||
return s < 10 ? '0' + s : s;
|
||||
}
|
||||
};
|
||||
|
||||
return format.replace(/d{1,4}|m{1,4}|yy(?:yy)?|([HhMs])\1?|"[^"]*"|'[^']*'/g, function(match) {
|
||||
return replacer[match] ? replacer[match](date) : match.slice(1, match.length - 1);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.date;
|
||||
}));
|
||||
113
static/src/js/lib/formValidation/validator/different.js
Executable file
113
static/src/js/lib/formValidation/validator/different.js
Executable file
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* different validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/different/
|
||||
* @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/different", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
different: {
|
||||
'default': 'Please enter a different value'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.different = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
field: 'field'
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind the validator on the live change of the field to compare with current one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - field: The name of field that will be used to compare with current one
|
||||
*/
|
||||
init: function(validator, $field, options) {
|
||||
var fields = options.field.split(',');
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var compareWith = validator.getFieldElements(fields[i]);
|
||||
validator.onLiveChange(compareWith, 'live_different', function() {
|
||||
var status = validator.getStatus($field, 'different');
|
||||
if (status !== validator.STATUS_NOT_VALIDATED) {
|
||||
validator.revalidateField($field);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Unbind the validator on the live change of the field to compare with current one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - field: The name of field that will be used to compare with current one
|
||||
*/
|
||||
destroy: function(validator, $field, options) {
|
||||
var fields = options.field.split(',');
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var compareWith = validator.getFieldElements(fields[i]);
|
||||
validator.offLiveChange(compareWith, 'live_different');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is different with given field's value
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - field: The name of field that will be used to compare with current one
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'different');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var fields = options.field.split(','),
|
||||
isValid = true;
|
||||
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var compareWith = validator.getFieldElements(fields[i]);
|
||||
if (compareWith == null || compareWith.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var compareValue = validator.getFieldValue(compareWith, 'different');
|
||||
if (value === compareValue) {
|
||||
isValid = false;
|
||||
} else if (compareValue !== '') {
|
||||
validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
|
||||
}
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.different;
|
||||
}));
|
||||
52
static/src/js/lib/formValidation/validator/digits.js
Executable file
52
static/src/js/lib/formValidation/validator/digits.js
Executable file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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;
|
||||
}));
|
||||
68
static/src/js/lib/formValidation/validator/ean.js
Executable file
68
static/src/js/lib/formValidation/validator/ean.js
Executable file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* ean validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/ean/
|
||||
* @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/ean", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
ean: {
|
||||
'default': 'Please enter a valid EAN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.ean = {
|
||||
/**
|
||||
* Validate EAN (International Article Number)
|
||||
* Examples:
|
||||
* - Valid: 73513537, 9780471117094, 4006381333931
|
||||
* - Invalid: 73513536
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/European_Article_Number
|
||||
* @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, 'ean');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var length = value.length,
|
||||
sum = 0,
|
||||
weight = (length === 8) ? [3, 1] : [1, 3];
|
||||
for (var i = 0; i < length - 1; i++) {
|
||||
sum += parseInt(value.charAt(i), 10) * weight[i % 2];
|
||||
}
|
||||
sum = (10 - sum % 10) % 10;
|
||||
return (sum + '' === value.charAt(length - 1));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.ean;
|
||||
}));
|
||||
86
static/src/js/lib/formValidation/validator/ein.js
Executable file
86
static/src/js/lib/formValidation/validator/ein.js
Executable file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* ein validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/ein/
|
||||
* @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/ein", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
ein: {
|
||||
'default': 'Please enter a valid EIN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.ein = {
|
||||
// The first two digits are called campus
|
||||
// See http://en.wikipedia.org/wiki/Employer_Identification_Number
|
||||
// http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes
|
||||
CAMPUS: {
|
||||
ANDOVER: ['10', '12'],
|
||||
ATLANTA: ['60', '67'],
|
||||
AUSTIN: ['50', '53'],
|
||||
BROOKHAVEN: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
|
||||
CINCINNATI: ['30', '32', '35', '36', '37', '38', '61'],
|
||||
FRESNO: ['15', '24'],
|
||||
KANSAS_CITY: ['40', '44'],
|
||||
MEMPHIS: ['94', '95'],
|
||||
OGDEN: ['80', '90'],
|
||||
PHILADELPHIA: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
|
||||
INTERNET: ['20', '26', '27', '45', '46'],
|
||||
SMALL_BUSINESS_ADMINISTRATION: ['31']
|
||||
},
|
||||
|
||||
/**
|
||||
* Validate EIN (Employer Identification Number) which is also known as
|
||||
* Federal Employer Identification Number (FEIN) or Federal Tax Identification Number
|
||||
*
|
||||
* @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 {Object|Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'ein');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!/^[0-9]{2}-?[0-9]{7}$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
// Check the first two digits
|
||||
var campus = value.substr(0, 2) + '';
|
||||
for (var key in this.CAMPUS) {
|
||||
if ($.inArray(campus, this.CAMPUS[key]) !== -1) {
|
||||
return {
|
||||
valid: true,
|
||||
campus: key
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.ein;
|
||||
}));
|
||||
115
static/src/js/lib/formValidation/validator/emailAddress.js
Executable file
115
static/src/js/lib/formValidation/validator/emailAddress.js
Executable file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* emailAddress validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/emailAddress/
|
||||
* @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/emailAddress", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
emailAddress: {
|
||||
'default': 'Please enter a valid email address'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.emailAddress = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
multiple: 'multiple',
|
||||
separator: 'separator'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
return ('email' === $field.attr('type'));
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if and only if the input value is a valid email address
|
||||
*
|
||||
* @param {FormValidation.Base} validator Validate plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} [options]
|
||||
* - multiple: Allow multiple email addresses, separated by a comma or semicolon; default is false.
|
||||
* - separator: Regex for character or characters expected as separator between addresses; default is comma /[,;]/, i.e. comma or semicolon.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'emailAddress');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Email address regular expression
|
||||
// http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
|
||||
var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
|
||||
allowMultiple = options.multiple === true || options.multiple === 'true';
|
||||
|
||||
if (allowMultiple) {
|
||||
var separator = options.separator || /[,;]/,
|
||||
addresses = this._splitEmailAddresses(value, separator);
|
||||
|
||||
for (var i = 0; i < addresses.length; i++) {
|
||||
if (!emailRegExp.test(addresses[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return emailRegExp.test(value);
|
||||
}
|
||||
},
|
||||
|
||||
_splitEmailAddresses: function(emailAddresses, separator) {
|
||||
var quotedFragments = emailAddresses.split(/"/),
|
||||
quotedFragmentCount = quotedFragments.length,
|
||||
emailAddressArray = [],
|
||||
nextEmailAddress = '';
|
||||
|
||||
for (var i = 0; i < quotedFragmentCount; i++) {
|
||||
if (i % 2 === 0) {
|
||||
var splitEmailAddressFragments = quotedFragments[i].split(separator),
|
||||
splitEmailAddressFragmentCount = splitEmailAddressFragments.length;
|
||||
|
||||
if (splitEmailAddressFragmentCount === 1) {
|
||||
nextEmailAddress += splitEmailAddressFragments[0];
|
||||
} else {
|
||||
emailAddressArray.push(nextEmailAddress + splitEmailAddressFragments[0]);
|
||||
|
||||
for (var j = 1; j < splitEmailAddressFragmentCount - 1; j++) {
|
||||
emailAddressArray.push(splitEmailAddressFragments[j]);
|
||||
}
|
||||
nextEmailAddress = splitEmailAddressFragments[splitEmailAddressFragmentCount - 1];
|
||||
}
|
||||
} else {
|
||||
nextEmailAddress += '"' + quotedFragments[i];
|
||||
if (i < quotedFragmentCount - 1) {
|
||||
nextEmailAddress += '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emailAddressArray.push(nextEmailAddress);
|
||||
return emailAddressArray;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.emailAddress;
|
||||
}));
|
||||
116
static/src/js/lib/formValidation/validator/file.js
Executable file
116
static/src/js/lib/formValidation/validator/file.js
Executable file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* file validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/file/
|
||||
* @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/file", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
file: {
|
||||
'default': 'Please choose a valid file'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.file = {
|
||||
html5Attributes: {
|
||||
extension: 'extension',
|
||||
maxfiles: 'maxFiles',
|
||||
minfiles: 'minFiles',
|
||||
maxsize: 'maxSize',
|
||||
minsize: 'minSize',
|
||||
maxtotalsize: 'maxTotalSize',
|
||||
mintotalsize: 'minTotalSize',
|
||||
message: 'message',
|
||||
type: 'type'
|
||||
},
|
||||
|
||||
/**
|
||||
* Validate upload file. Use HTML 5 API if the browser supports
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - extension: The allowed extensions, separated by a comma
|
||||
* - maxFiles: The maximum number of files
|
||||
* - minFiles: The minimum number of files
|
||||
* - maxSize: The maximum size in bytes
|
||||
* - minSize: The minimum size in bytes
|
||||
* - maxTotalSize: The maximum size in bytes for all files
|
||||
* - minTotalSize: The minimum size in bytes for all files
|
||||
* - message: The invalid message
|
||||
* - type: The allowed MIME type, separated by a comma
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'file');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var ext,
|
||||
extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
|
||||
types = options.type ? options.type.toLowerCase().split(',') : null,
|
||||
html5 = (window.File && window.FileList && window.FileReader);
|
||||
|
||||
if (html5) {
|
||||
// Get FileList instance
|
||||
var files = $field.get(0).files,
|
||||
total = files.length,
|
||||
totalSize = 0;
|
||||
|
||||
if ((options.maxFiles && total > parseInt(options.maxFiles, 10)) // Check the maxFiles
|
||||
|| (options.minFiles && total < parseInt(options.minFiles, 10))) // Check the minFiles
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < total; i++) {
|
||||
totalSize += files[i].size;
|
||||
ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
|
||||
|
||||
if ((options.minSize && files[i].size < parseInt(options.minSize, 10)) // Check the minSize
|
||||
|| (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) // Check the maxSize
|
||||
|| (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) // Check file extension
|
||||
|| (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1)) // Check file type
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((options.maxTotalSize && totalSize > parseInt(options.maxTotalSize, 10)) // Check the maxTotalSize
|
||||
|| (options.minTotalSize && totalSize < parseInt(options.minTotalSize, 10))) // Check the minTotalSize
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Check file extension
|
||||
ext = value.substr(value.lastIndexOf('.') + 1);
|
||||
if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.file;
|
||||
}));
|
||||
101
static/src/js/lib/formValidation/validator/greaterThan.js
Executable file
101
static/src/js/lib/formValidation/validator/greaterThan.js
Executable file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* greaterThan validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/greaterThan/
|
||||
* @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/greaterThan", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
greaterThan: {
|
||||
'default': 'Please enter a value greater than or equal to %s',
|
||||
notInclusive: 'Please enter a value greater than %s'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.greaterThan = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
value: 'value',
|
||||
inclusive: 'inclusive'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
var type = $field.attr('type'),
|
||||
min = $field.attr('min');
|
||||
if (min && type !== 'date') {
|
||||
return {
|
||||
value: min
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is greater than or equals to given number
|
||||
*
|
||||
* @param {FormValidation.Base} validator Validate plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - value: Define the number to compare with. It can be
|
||||
* - A number
|
||||
* - Name of field which its value defines the number
|
||||
* - Name of callback function that returns the number
|
||||
* - A callback function that returns the number
|
||||
*
|
||||
* - inclusive [optional]: Can be true or false. Default is true
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'greaterThan');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = this._format(value);
|
||||
if (!$.isNumeric(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
|
||||
compareToValue = this._format(compareTo);
|
||||
|
||||
value = parseFloat(value);
|
||||
return (options.inclusive === true || options.inclusive === undefined)
|
||||
? {
|
||||
valid: value >= compareToValue,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].greaterThan['default'], compareTo)
|
||||
}
|
||||
: {
|
||||
valid: value > compareToValue,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].greaterThan.notInclusive, compareTo)
|
||||
};
|
||||
},
|
||||
|
||||
_format: function(value) {
|
||||
return (value + '').replace(',', '.');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.greaterThan;
|
||||
}));
|
||||
65
static/src/js/lib/formValidation/validator/grid.js
Executable file
65
static/src/js/lib/formValidation/validator/grid.js
Executable file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* grid validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/grid/
|
||||
* @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/grid", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
grid: {
|
||||
'default': 'Please enter a valid GRId number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.grid = {
|
||||
/**
|
||||
* Validate GRId (Global Release Identifier)
|
||||
* Examples:
|
||||
* - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
|
||||
* - Invalid: A1-2425G-ABC1234002-Q
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/Global_Release_Identifier
|
||||
* @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, 'grid');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = value.toUpperCase();
|
||||
if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
|
||||
return false;
|
||||
}
|
||||
value = value.replace(/\s/g, '').replace(/-/g, '');
|
||||
if ('GRID:' === value.substr(0, 5)) {
|
||||
value = value.substr(5);
|
||||
}
|
||||
return FormValidation.Helper.mod37And36(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.grid;
|
||||
}));
|
||||
53
static/src/js/lib/formValidation/validator/hex.js
Executable file
53
static/src/js/lib/formValidation/validator/hex.js
Executable file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 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;
|
||||
}));
|
||||
271
static/src/js/lib/formValidation/validator/iban.js
Executable file
271
static/src/js/lib/formValidation/validator/iban.js
Executable file
@@ -0,0 +1,271 @@
|
||||
/**
|
||||
* iban validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/iban/
|
||||
* @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/iban", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
iban: {
|
||||
'default': 'Please enter a valid IBAN number',
|
||||
country: 'Please enter a valid IBAN number in %s',
|
||||
countries: {
|
||||
AD: 'Andorra',
|
||||
AE: 'United Arab Emirates',
|
||||
AL: 'Albania',
|
||||
AO: 'Angola',
|
||||
AT: 'Austria',
|
||||
AZ: 'Azerbaijan',
|
||||
BA: 'Bosnia and Herzegovina',
|
||||
BE: 'Belgium',
|
||||
BF: 'Burkina Faso',
|
||||
BG: 'Bulgaria',
|
||||
BH: 'Bahrain',
|
||||
BI: 'Burundi',
|
||||
BJ: 'Benin',
|
||||
BR: 'Brazil',
|
||||
CH: 'Switzerland',
|
||||
CI: 'Ivory Coast',
|
||||
CM: 'Cameroon',
|
||||
CR: 'Costa Rica',
|
||||
CV: 'Cape Verde',
|
||||
CY: 'Cyprus',
|
||||
CZ: 'Czech Republic',
|
||||
DE: 'Germany',
|
||||
DK: 'Denmark',
|
||||
DO: 'Dominican Republic',
|
||||
DZ: 'Algeria',
|
||||
EE: 'Estonia',
|
||||
ES: 'Spain',
|
||||
FI: 'Finland',
|
||||
FO: 'Faroe Islands',
|
||||
FR: 'France',
|
||||
GB: 'United Kingdom',
|
||||
GE: 'Georgia',
|
||||
GI: 'Gibraltar',
|
||||
GL: 'Greenland',
|
||||
GR: 'Greece',
|
||||
GT: 'Guatemala',
|
||||
HR: 'Croatia',
|
||||
HU: 'Hungary',
|
||||
IE: 'Ireland',
|
||||
IL: 'Israel',
|
||||
IR: 'Iran',
|
||||
IS: 'Iceland',
|
||||
IT: 'Italy',
|
||||
JO: 'Jordan',
|
||||
KW: 'Kuwait',
|
||||
KZ: 'Kazakhstan',
|
||||
LB: 'Lebanon',
|
||||
LI: 'Liechtenstein',
|
||||
LT: 'Lithuania',
|
||||
LU: 'Luxembourg',
|
||||
LV: 'Latvia',
|
||||
MC: 'Monaco',
|
||||
MD: 'Moldova',
|
||||
ME: 'Montenegro',
|
||||
MG: 'Madagascar',
|
||||
MK: 'Macedonia',
|
||||
ML: 'Mali',
|
||||
MR: 'Mauritania',
|
||||
MT: 'Malta',
|
||||
MU: 'Mauritius',
|
||||
MZ: 'Mozambique',
|
||||
NL: 'Netherlands',
|
||||
NO: 'Norway',
|
||||
PK: 'Pakistan',
|
||||
PL: 'Poland',
|
||||
PS: 'Palestine',
|
||||
PT: 'Portugal',
|
||||
QA: 'Qatar',
|
||||
RO: 'Romania',
|
||||
RS: 'Serbia',
|
||||
SA: 'Saudi Arabia',
|
||||
SE: 'Sweden',
|
||||
SI: 'Slovenia',
|
||||
SK: 'Slovakia',
|
||||
SM: 'San Marino',
|
||||
SN: 'Senegal',
|
||||
TN: 'Tunisia',
|
||||
TR: 'Turkey',
|
||||
VG: 'Virgin Islands, British'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.iban = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
country: 'country'
|
||||
},
|
||||
|
||||
// http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
|
||||
// http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
|
||||
REGEX: {
|
||||
AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
|
||||
AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
|
||||
AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
|
||||
AO: 'AO[0-9]{2}[0-9]{21}', // Angola
|
||||
AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
|
||||
AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
|
||||
BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
|
||||
BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
|
||||
BF: 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
|
||||
BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
|
||||
BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
|
||||
BI: 'BI[0-9]{2}[0-9]{12}', // Burundi
|
||||
BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
|
||||
BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
|
||||
CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
|
||||
CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
|
||||
CM: 'CM[0-9]{2}[0-9]{23}', // Cameroon
|
||||
CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
|
||||
CV: 'CV[0-9]{2}[0-9]{21}', // Cape Verde
|
||||
CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
|
||||
CZ: 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
|
||||
DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
|
||||
DK: 'DK[0-9]{2}[0-9]{14}', // Denmark
|
||||
DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
|
||||
DZ: 'DZ[0-9]{2}[0-9]{20}', // Algeria
|
||||
EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
|
||||
ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
|
||||
FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
|
||||
FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
|
||||
FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
|
||||
GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
|
||||
GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
|
||||
GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
|
||||
GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland
|
||||
GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
|
||||
GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
|
||||
HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
|
||||
HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
|
||||
IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
|
||||
IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
|
||||
IR: 'IR[0-9]{2}[0-9]{22}', // Iran
|
||||
IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
|
||||
IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
|
||||
JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
|
||||
KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
|
||||
KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
|
||||
LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
|
||||
LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
|
||||
LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
|
||||
LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
|
||||
LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
|
||||
MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
|
||||
MD: 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
|
||||
ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
|
||||
MG: 'MG[0-9]{2}[0-9]{23}', // Madagascar
|
||||
MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
|
||||
ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
|
||||
MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
|
||||
MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
|
||||
MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}', // Mauritius
|
||||
MZ: 'MZ[0-9]{2}[0-9]{21}', // Mozambique
|
||||
NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
|
||||
NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
|
||||
PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
|
||||
PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
|
||||
PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
|
||||
PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
|
||||
QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
|
||||
RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
|
||||
RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
|
||||
SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
|
||||
SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
|
||||
SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
|
||||
SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
|
||||
SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
|
||||
SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
|
||||
TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
|
||||
TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
|
||||
VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
|
||||
},
|
||||
|
||||
/**
|
||||
* Validate an International Bank Account Number (IBAN)
|
||||
* To test it, take the sample IBAN from
|
||||
* http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
|
||||
*
|
||||
* @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
|
||||
* - country: The ISO 3166-1 country code. It can be
|
||||
* - A country code
|
||||
* - Name of field which its value defines the country code
|
||||
* - Name of callback function that returns the country code
|
||||
* - A callback function that returns the country code
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'iban');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
|
||||
var country = options.country;
|
||||
if (!country) {
|
||||
country = value.substr(0, 2);
|
||||
} else if (typeof country !== 'string' || !this.REGEX[country]) {
|
||||
// Determine the country code
|
||||
country = validator.getDynamicOption($field, country);
|
||||
}
|
||||
|
||||
var locale = validator.getLocale();
|
||||
if (!this.REGEX[country]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
|
||||
return {
|
||||
valid: false,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].iban.country, FormValidation.I18n[locale].iban.countries[country])
|
||||
};
|
||||
}
|
||||
|
||||
value = value.substr(4) + value.substr(0, 4);
|
||||
value = $.map(value.split(''), function(n) {
|
||||
var code = n.charCodeAt(0);
|
||||
return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
|
||||
// Replace A, B, C, ..., Z with 10, 11, ..., 35
|
||||
? (code - 'A'.charCodeAt(0) + 10)
|
||||
: n;
|
||||
});
|
||||
value = value.join('');
|
||||
|
||||
var temp = parseInt(value.substr(0, 1), 10),
|
||||
length = value.length;
|
||||
for (var i = 1; i < length; ++i) {
|
||||
temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
|
||||
}
|
||||
|
||||
return {
|
||||
valid: (temp === 1),
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].iban.country, FormValidation.I18n[locale].iban.countries[country])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.iban;
|
||||
}));
|
||||
1453
static/src/js/lib/formValidation/validator/id.js
Executable file
1453
static/src/js/lib/formValidation/validator/id.js
Executable file
File diff suppressed because it is too large
Load Diff
96
static/src/js/lib/formValidation/validator/identical.js
Executable file
96
static/src/js/lib/formValidation/validator/identical.js
Executable file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* identical validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/identical/
|
||||
* @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/identical", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
identical: {
|
||||
'default': 'Please enter the same value'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.identical = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
field: 'field'
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind the validator on the live change of the field to compare with current one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - field: The name of field that will be used to compare with current one
|
||||
*/
|
||||
init: function(validator, $field, options) {
|
||||
var compareWith = validator.getFieldElements(options.field);
|
||||
validator.onLiveChange(compareWith, 'live_identical', function() {
|
||||
var status = validator.getStatus($field, 'identical');
|
||||
if (status !== validator.STATUS_NOT_VALIDATED) {
|
||||
validator.revalidateField($field);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Unbind the validator on the live change of the field to compare with current one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - field: The name of field that will be used to compare with current one
|
||||
*/
|
||||
destroy: function(validator, $field, options) {
|
||||
var compareWith = validator.getFieldElements(options.field);
|
||||
validator.offLiveChange(compareWith, 'live_identical');
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if input value equals to value of particular one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - field: The name of field that will be used to compare with current one
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'identical'),
|
||||
compareWith = validator.getFieldElements(options.field);
|
||||
if (compareWith === null || compareWith.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var compareValue = validator.getFieldValue(compareWith, 'identical');
|
||||
if (value === compareValue) {
|
||||
validator.updateStatus(compareWith, validator.STATUS_VALID, 'identical');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.identical;
|
||||
}));
|
||||
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;
|
||||
}));
|
||||
73
static/src/js/lib/formValidation/validator/imo.js
Executable file
73
static/src/js/lib/formValidation/validator/imo.js
Executable file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* imo validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/imo/
|
||||
* @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/imo", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
imo: {
|
||||
'default': 'Please enter a valid IMO number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.imo = {
|
||||
/**
|
||||
* Validate IMO (International Maritime Organization)
|
||||
* Examples:
|
||||
* - Valid: IMO 8814275, IMO 9176187
|
||||
* - Invalid: IMO 8814274
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/IMO_Number
|
||||
* @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, 'imo');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!/^IMO \d{7}$/i.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab just the digits
|
||||
var sum = 0,
|
||||
digits = value.replace(/^.*(\d{7})$/, '$1');
|
||||
|
||||
// Go over each char, multiplying by the inverse of it's position
|
||||
// IMO 9176187
|
||||
// (9 * 7) + (1 * 6) + (7 * 5) + (6 * 4) + (1 * 3) + (8 * 2) = 147
|
||||
// Take the last digit of that, that's the check digit (7)
|
||||
for (var i = 6; i >= 1; i--) {
|
||||
sum += (digits.slice((6 - i), -i) * (i + 1));
|
||||
}
|
||||
|
||||
return sum % 10 === parseInt(digits.charAt(6), 10);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.imo;
|
||||
}));
|
||||
60
static/src/js/lib/formValidation/validator/integer.js
Executable file
60
static/src/js/lib/formValidation/validator/integer.js
Executable file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* integer validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/integer/
|
||||
* @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/integer", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
integer: {
|
||||
'default': 'Please enter a valid number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.integer = {
|
||||
enableByHtml5: function($field) {
|
||||
return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is an integer
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following key:
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = validator.getFieldValue($field, 'integer');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.integer;
|
||||
}));
|
||||
92
static/src/js/lib/formValidation/validator/ip.js
Executable file
92
static/src/js/lib/formValidation/validator/ip.js
Executable file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* ip validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/ip/
|
||||
* @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/ip", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
ip: {
|
||||
'default': 'Please enter a valid IP address',
|
||||
ipv4: 'Please enter a valid IPv4 address',
|
||||
ipv6: 'Please enter a valid IPv6 address'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.ip = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
ipv4: 'ipv4',
|
||||
ipv6: 'ipv6'
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is a IP address.
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - ipv4: Enable IPv4 validator, default to true
|
||||
* - ipv6: Enable IPv6 validator, default to true
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'ip');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
options = $.extend({}, { ipv4: true, ipv6: true }, options);
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
||||
ipv6Regex = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,
|
||||
valid = false,
|
||||
message;
|
||||
|
||||
switch (true) {
|
||||
case (options.ipv4 && !options.ipv6):
|
||||
valid = ipv4Regex.test(value);
|
||||
message = options.message || FormValidation.I18n[locale].ip.ipv4;
|
||||
break;
|
||||
|
||||
case (!options.ipv4 && options.ipv6):
|
||||
valid = ipv6Regex.test(value);
|
||||
message = options.message || FormValidation.I18n[locale].ip.ipv6;
|
||||
break;
|
||||
|
||||
case (options.ipv4 && options.ipv6):
|
||||
/* falls through */
|
||||
default:
|
||||
valid = ipv4Regex.test(value) || ipv6Regex.test(value);
|
||||
message = options.message || FormValidation.I18n[locale].ip['default'];
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
valid: valid,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.ip;
|
||||
}));
|
||||
114
static/src/js/lib/formValidation/validator/isbn.js
Executable file
114
static/src/js/lib/formValidation/validator/isbn.js
Executable file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* isbn validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/isbn/
|
||||
* @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/isbn", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
isbn: {
|
||||
'default': 'Please enter a valid ISBN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.isbn = {
|
||||
/**
|
||||
* Return true if the input value is a valid ISBN 10 or ISBN 13 number
|
||||
* Examples:
|
||||
* - Valid:
|
||||
* ISBN 10: 99921-58-10-7, 9971-5-0210-0, 960-425-059-0, 80-902734-1-6, 85-359-0277-5, 1-84356-028-3, 0-684-84328-5, 0-8044-2957-X, 0-85131-041-9, 0-943396-04-2, 0-9752298-0-X
|
||||
* ISBN 13: 978-0-306-40615-7
|
||||
* - Invalid:
|
||||
* ISBN 10: 99921-58-10-6
|
||||
* ISBN 13: 978-0-306-40615-6
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
||||
* @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, 'isbn');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
|
||||
// Groups are separated by a hyphen or a space
|
||||
var type;
|
||||
switch (true) {
|
||||
case /^\d{9}[\dX]$/.test(value):
|
||||
case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
|
||||
case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
|
||||
type = 'ISBN10';
|
||||
break;
|
||||
case /^(978|979)\d{9}[\dX]$/.test(value):
|
||||
case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
|
||||
case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
|
||||
type = 'ISBN13';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Replace all special characters except digits and X
|
||||
value = value.replace(/[^0-9X]/gi, '');
|
||||
var chars = value.split(''),
|
||||
length = chars.length,
|
||||
sum = 0,
|
||||
i,
|
||||
checksum;
|
||||
|
||||
switch (type) {
|
||||
case 'ISBN10':
|
||||
sum = 0;
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
sum += parseInt(chars[i], 10) * (10 - i);
|
||||
}
|
||||
checksum = 11 - (sum % 11);
|
||||
if (checksum === 11) {
|
||||
checksum = 0;
|
||||
} else if (checksum === 10) {
|
||||
checksum = 'X';
|
||||
}
|
||||
return (checksum + '' === chars[length - 1]);
|
||||
|
||||
case 'ISBN13':
|
||||
sum = 0;
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
|
||||
}
|
||||
checksum = 10 - (sum % 10);
|
||||
if (checksum === 10) {
|
||||
checksum = '0';
|
||||
}
|
||||
return (checksum + '' === chars[length - 1]);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.isbn;
|
||||
}));
|
||||
87
static/src/js/lib/formValidation/validator/isin.js
Executable file
87
static/src/js/lib/formValidation/validator/isin.js
Executable file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* isin validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/isin/
|
||||
* @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/isin", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
isin: {
|
||||
'default': 'Please enter a valid ISIN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.isin = {
|
||||
// Available country codes
|
||||
// See http://isin.net/country-codes/
|
||||
COUNTRY_CODES: 'AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW',
|
||||
|
||||
/**
|
||||
* Validate an ISIN (International Securities Identification Number)
|
||||
* Examples:
|
||||
* - Valid: US0378331005, AU0000XVGZA3, GB0002634946
|
||||
* - Invalid: US0378331004, AA0000XVGZA3
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
|
||||
* @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, 'isin');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = value.toUpperCase();
|
||||
var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
|
||||
if (!regex.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var converted = '',
|
||||
length = value.length;
|
||||
// Convert letters to number
|
||||
for (var i = 0; i < length - 1; i++) {
|
||||
var c = value.charCodeAt(i);
|
||||
converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
|
||||
}
|
||||
|
||||
var digits = '',
|
||||
n = converted.length,
|
||||
group = (n % 2 !== 0) ? 0 : 1;
|
||||
for (i = 0; i < n; i++) {
|
||||
digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
for (i = 0; i < digits.length; i++) {
|
||||
sum += parseInt(digits.charAt(i), 10);
|
||||
}
|
||||
sum = (10 - (sum % 10)) % 10;
|
||||
return sum + '' === value.charAt(length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.isin;
|
||||
}));
|
||||
87
static/src/js/lib/formValidation/validator/ismn.js
Executable file
87
static/src/js/lib/formValidation/validator/ismn.js
Executable file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* ismn validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/ismn/
|
||||
* @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/ismn", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
ismn: {
|
||||
'default': 'Please enter a valid ISMN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.ismn = {
|
||||
/**
|
||||
* Validate ISMN (International Standard Music Number)
|
||||
* Examples:
|
||||
* - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
|
||||
* - Invalid: 9790060115614
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
|
||||
* @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, 'ismn');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Groups are separated by a hyphen or a space
|
||||
var type;
|
||||
switch (true) {
|
||||
case /^M\d{9}$/.test(value):
|
||||
case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
|
||||
case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
|
||||
type = 'ISMN10';
|
||||
break;
|
||||
case /^9790\d{9}$/.test(value):
|
||||
case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
|
||||
case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
|
||||
type = 'ISMN13';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if ('ISMN10' === type) {
|
||||
value = '9790' + value.substr(1);
|
||||
}
|
||||
|
||||
// Replace all special characters except digits
|
||||
value = value.replace(/[^0-9]/gi, '');
|
||||
var length = value.length,
|
||||
sum = 0,
|
||||
weight = [1, 3];
|
||||
for (var i = 0; i < length - 1; i++) {
|
||||
sum += parseInt(value.charAt(i), 10) * weight[i % 2];
|
||||
}
|
||||
sum = 10 - sum % 10;
|
||||
return (sum + '' === value.charAt(length - 1));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.ismn;
|
||||
}));
|
||||
74
static/src/js/lib/formValidation/validator/issn.js
Executable file
74
static/src/js/lib/formValidation/validator/issn.js
Executable file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* issn validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/issn/
|
||||
* @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/issn", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
issn: {
|
||||
'default': 'Please enter a valid ISSN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.issn = {
|
||||
/**
|
||||
* Validate ISSN (International Standard Serial Number)
|
||||
* Examples:
|
||||
* - Valid: 0378-5955, 0024-9319, 0032-1478
|
||||
* - Invalid: 0032-147X
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
|
||||
* @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, 'issn');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Groups are separated by a hyphen or a space
|
||||
if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Replace all special characters except digits and X
|
||||
value = value.replace(/[^0-9X]/gi, '');
|
||||
var chars = value.split(''),
|
||||
length = chars.length,
|
||||
sum = 0;
|
||||
|
||||
if (chars[7] === 'X') {
|
||||
chars[7] = 10;
|
||||
}
|
||||
for (var i = 0; i < length; i++) {
|
||||
sum += parseInt(chars[i], 10) * (8 - i);
|
||||
}
|
||||
return (sum % 11 === 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.issn;
|
||||
}));
|
||||
101
static/src/js/lib/formValidation/validator/lessThan.js
Executable file
101
static/src/js/lib/formValidation/validator/lessThan.js
Executable file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* lessThan validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/lessThan/
|
||||
* @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/lessThan", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
lessThan: {
|
||||
'default': 'Please enter a value less than or equal to %s',
|
||||
notInclusive: 'Please enter a value less than %s'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.lessThan = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
value: 'value',
|
||||
inclusive: 'inclusive'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
var type = $field.attr('type'),
|
||||
max = $field.attr('max');
|
||||
if (max && type !== 'date') {
|
||||
return {
|
||||
value: max
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is less than or equal to given number
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - value: The number used to compare to. It can be
|
||||
* - A number
|
||||
* - Name of field which its value defines the number
|
||||
* - Name of callback function that returns the number
|
||||
* - A callback function that returns the number
|
||||
*
|
||||
* - inclusive [optional]: Can be true or false. Default is true
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'lessThan');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = this._format(value);
|
||||
if (!$.isNumeric(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
|
||||
compareToValue = this._format(compareTo);
|
||||
|
||||
value = parseFloat(value);
|
||||
return (options.inclusive === true || options.inclusive === undefined)
|
||||
? {
|
||||
valid: value <= compareToValue,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].lessThan['default'], compareTo)
|
||||
}
|
||||
: {
|
||||
valid: value < compareToValue,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].lessThan.notInclusive, compareTo)
|
||||
};
|
||||
},
|
||||
|
||||
_format: function(value) {
|
||||
return (value + '').replace(',', '.');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.lessThan;
|
||||
}));
|
||||
53
static/src/js/lib/formValidation/validator/mac.js
Executable file
53
static/src/js/lib/formValidation/validator/mac.js
Executable file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* mac validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/mac/
|
||||
* @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/mac", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
mac: {
|
||||
'default': 'Please enter a valid MAC address'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.mac = {
|
||||
/**
|
||||
* Return true if the input value is a MAC address.
|
||||
*
|
||||
* @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, 'mac');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.mac;
|
||||
}));
|
||||
111
static/src/js/lib/formValidation/validator/meid.js
Executable file
111
static/src/js/lib/formValidation/validator/meid.js
Executable file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* meid validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/meid/
|
||||
* @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/meid", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
meid: {
|
||||
'default': 'Please enter a valid MEID number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.meid = {
|
||||
/**
|
||||
* Validate MEID (Mobile Equipment Identifier)
|
||||
* Examples:
|
||||
* - Valid: 293608736500703710, 29360-87365-0070-3710, AF0123450ABCDE, AF-012345-0ABCDE
|
||||
* - Invalid: 2936087365007037101
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/Mobile_equipment_identifier
|
||||
* @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, 'meid');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
// 14 digit hex representation (no check digit)
|
||||
case /^[0-9A-F]{15}$/i.test(value):
|
||||
// 14 digit hex representation + dashes or spaces (no check digit)
|
||||
case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}[- ][0-9A-F]$/i.test(value):
|
||||
// 18 digit decimal representation (no check digit)
|
||||
case /^\d{19}$/.test(value):
|
||||
// 18 digit decimal representation + dashes or spaces (no check digit)
|
||||
case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}[- ]\d$/.test(value):
|
||||
// Grab the check digit
|
||||
var cd = value.charAt(value.length - 1);
|
||||
|
||||
// Strip any non-hex chars
|
||||
value = value.replace(/[- ]/g, '');
|
||||
|
||||
// If it's all digits, luhn base 10 is used
|
||||
if (value.match(/^\d*$/i)) {
|
||||
return FormValidation.Helper.luhn(value);
|
||||
}
|
||||
|
||||
// Strip the check digit
|
||||
value = value.slice(0, -1);
|
||||
|
||||
// Get every other char, and double it
|
||||
var cdCalc = '';
|
||||
for (var i = 1; i <= 13; i += 2) {
|
||||
cdCalc += (parseInt(value.charAt(i), 16) * 2).toString(16);
|
||||
}
|
||||
|
||||
// Get the sum of each char in the string
|
||||
var sum = 0;
|
||||
for (i = 0; i < cdCalc.length; i++) {
|
||||
sum += parseInt(cdCalc.charAt(i), 16);
|
||||
}
|
||||
|
||||
// If the last digit of the calc is 0, the check digit is 0
|
||||
return (sum % 10 === 0)
|
||||
? (cd === '0')
|
||||
// Subtract it from the next highest 10s number (64 goes to 70) and subtract the sum
|
||||
// Double it and turn it into a hex char
|
||||
: (cd === ((Math.floor((sum + 10) / 10) * 10 - sum) * 2).toString(16));
|
||||
|
||||
// 14 digit hex representation (no check digit)
|
||||
case /^[0-9A-F]{14}$/i.test(value):
|
||||
// 14 digit hex representation + dashes or spaces (no check digit)
|
||||
case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}$/i.test(value):
|
||||
// 18 digit decimal representation (no check digit)
|
||||
case /^\d{18}$/.test(value):
|
||||
// 18 digit decimal representation + dashes or spaces (no check digit)
|
||||
case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}$/.test(value):
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.meid;
|
||||
}));
|
||||
65
static/src/js/lib/formValidation/validator/notEmpty.js
Executable file
65
static/src/js/lib/formValidation/validator/notEmpty.js
Executable file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* notEmpty validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/notEmpty/
|
||||
* @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/notEmpty", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
notEmpty: {
|
||||
'default': 'Please enter a value'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.notEmpty = {
|
||||
enableByHtml5: function($field) {
|
||||
var required = $field.attr('required') + '';
|
||||
return ('required' === required || 'true' === required);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if input value is empty or not
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var type = $field.attr('type');
|
||||
if ('radio' === type || 'checkbox' === type) {
|
||||
var ns = validator.getNamespace();
|
||||
return validator
|
||||
.getFieldElements($field.attr('data-' + ns + '-field'))
|
||||
.filter(':checked')
|
||||
.length > 0;
|
||||
}
|
||||
|
||||
if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $.trim($field.val()) !== '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.notEmpty;
|
||||
}));
|
||||
71
static/src/js/lib/formValidation/validator/numeric.js
Executable file
71
static/src/js/lib/formValidation/validator/numeric.js
Executable file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* numeric validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/numeric/
|
||||
* @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/numeric", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
numeric: {
|
||||
'default': 'Please enter a valid float number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.numeric = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
separator: 'separator'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* Validate decimal number
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consist of key:
|
||||
* - message: The invalid message
|
||||
* - separator: The decimal separator. Can be "." (default), ","
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = validator.getFieldValue($field, 'numeric');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
var separator = options.separator || '.';
|
||||
if (separator !== '.') {
|
||||
value = value.replace(separator, '.');
|
||||
}
|
||||
|
||||
return !isNaN(parseFloat(value)) && isFinite(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.numeric;
|
||||
}));
|
||||
243
static/src/js/lib/formValidation/validator/phone.js
Executable file
243
static/src/js/lib/formValidation/validator/phone.js
Executable file
@@ -0,0 +1,243 @@
|
||||
/**
|
||||
* phone validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/phone/
|
||||
* @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/phone", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
phone: {
|
||||
'default': 'Please enter a valid phone number',
|
||||
country: 'Please enter a valid phone number in %s',
|
||||
countries: {
|
||||
AE: 'United Arab Emirates',
|
||||
BG: 'Bulgaria',
|
||||
BR: 'Brazil',
|
||||
CN: 'China',
|
||||
CZ: 'Czech Republic',
|
||||
DE: 'Germany',
|
||||
DK: 'Denmark',
|
||||
ES: 'Spain',
|
||||
FR: 'France',
|
||||
GB: 'United Kingdom',
|
||||
IN: 'India',
|
||||
MA: 'Morocco',
|
||||
NL: 'Netherlands',
|
||||
PK: 'Pakistan',
|
||||
RO: 'Romania',
|
||||
RU: 'Russia',
|
||||
SK: 'Slovakia',
|
||||
TH: 'Thailand',
|
||||
US: 'USA',
|
||||
VE: 'Venezuela'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.phone = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
country: 'country'
|
||||
},
|
||||
|
||||
// The supported countries
|
||||
COUNTRY_CODES: ['AE', 'BG', 'BR', 'CN', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'IN', 'MA', 'NL', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
|
||||
|
||||
/**
|
||||
* Return true if the input value contains a valid phone number for the country
|
||||
* selected in the options
|
||||
*
|
||||
* @param {FormValidation.Base} validator Validate plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consist of key:
|
||||
* - message: The invalid message
|
||||
* - country: The ISO-3166 country code. It can be
|
||||
* - A country code
|
||||
* - Name of field which its value defines the country code
|
||||
* - Name of callback function that returns the country code
|
||||
* - A callback function that returns the country code
|
||||
*
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'phone');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
country = options.country;
|
||||
if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
|
||||
// Try to determine the country
|
||||
country = validator.getDynamicOption($field, country);
|
||||
}
|
||||
|
||||
if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var isValid = true;
|
||||
switch (country.toUpperCase()) {
|
||||
case 'AE':
|
||||
// Test: http://regexr.com/39tak
|
||||
value = $.trim(value);
|
||||
isValid = (/^(((\+|00)?971[\s\.-]?(\(0\)[\s\.-]?)?|0)(\(5(0|2|5|6)\)|5(0|2|5|6)|2|3|4|6|7|9)|60)([\s\.-]?[0-9]){7}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'BG':
|
||||
// Test cases can be found here: https://regex101.com/r/yE6vN4/1
|
||||
// See http://en.wikipedia.org/wiki/Telephone_numbers_in_Bulgaria
|
||||
value = value.replace(/\+|\s|-|\/|\(|\)/gi,'');
|
||||
isValid = (/^(0|359|00)(((700|900)[0-9]{5}|((800)[0-9]{5}|(800)[0-9]{4}))|(87|88|89)([0-9]{7})|((2[0-9]{7})|(([3-9][0-9])(([0-9]{6})|([0-9]{5})))))$/).test(value);
|
||||
break;
|
||||
|
||||
case 'BR':
|
||||
// Test: http://regexr.com/399m1
|
||||
value = $.trim(value);
|
||||
isValid = (/^(([\d]{4}[-.\s]{1}[\d]{2,3}[-.\s]{1}[\d]{2}[-.\s]{1}[\d]{2})|([\d]{4}[-.\s]{1}[\d]{3}[-.\s]{1}[\d]{4})|((\(?\+?[0-9]{2}\)?\s?)?(\(?\d{2}\)?\s?)?\d{4,5}[-.\s]?\d{4}))$/).test(value);
|
||||
break;
|
||||
|
||||
case 'CN':
|
||||
// http://regexr.com/39dq4
|
||||
value = $.trim(value);
|
||||
isValid = (/^((00|\+)?(86(?:-| )))?((\d{11})|(\d{3}[- ]{1}\d{4}[- ]{1}\d{4})|((\d{2,4}[- ]){1}(\d{7,8}|(\d{3,4}[- ]{1}\d{4}))([- ]{1}\d{1,4})?))$/).test(value);
|
||||
break;
|
||||
|
||||
case 'CZ':
|
||||
// Test: http://regexr.com/39hhl
|
||||
isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'DE':
|
||||
// Test: http://regexr.com/39pkg
|
||||
value = $.trim(value);
|
||||
isValid = (/^(((((((00|\+)49[ \-/]?)|0)[1-9][0-9]{1,4})[ \-/]?)|((((00|\+)49\()|\(0)[1-9][0-9]{1,4}\)[ \-/]?))[0-9]{1,7}([ \-/]?[0-9]{1,5})?)$/).test(value);
|
||||
break;
|
||||
|
||||
case 'DK':
|
||||
// Mathing DK phone numbers with country code in 1 of 3 formats and an
|
||||
// 8 digit phone number not starting with a 0 or 1. Can have 1 space
|
||||
// between each character except inside the country code.
|
||||
// Test: http://regex101.com/r/sS8fO4/1
|
||||
value = $.trim(value);
|
||||
isValid = (/^(\+45|0045|\(45\))?\s?[2-9](\s?\d){7}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'ES':
|
||||
// http://regex101.com/r/rB9mA9/1
|
||||
// Telephone numbers in Spain go like this:
|
||||
// 9: Landline phones and special prefixes.
|
||||
// 6, 7: Mobile phones.
|
||||
// 5: VoIP lines.
|
||||
// 8: Premium-rate services.
|
||||
// There are also special 5-digit and 3-digit numbers, but
|
||||
// maybe it would be overkill to include them all.
|
||||
value = $.trim(value);
|
||||
isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:5|6|7|8|9)(?:\d\D?){8}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'FR':
|
||||
// http://regexr.com/39a2p
|
||||
value = $.trim(value);
|
||||
isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'GB':
|
||||
// http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
|
||||
// Test: http://regexr.com/38uhv
|
||||
value = $.trim(value);
|
||||
isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
|
||||
break;
|
||||
|
||||
case 'IN':
|
||||
// http://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number
|
||||
// Test: http://regex101.com/r/qL6eZ5/1
|
||||
// May begin with +91. Supports mobile and land line numbers
|
||||
value = $.trim(value);
|
||||
isValid = (/((\+?)((0[ -]+)*|(91 )*)(\d{12}|\d{10}))|\d{5}([- ]*)\d{6}/).test(value);
|
||||
break;
|
||||
|
||||
case 'MA':
|
||||
// http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
|
||||
// Test: http://regexr.com/399n8
|
||||
value = $.trim(value);
|
||||
isValid = (/^(?:(?:(?:\+|00)212[\s]?(?:[\s]?\(0\)[\s]?)?)|0){1}(?:5[\s.-]?[2-3]|6[\s.-]?[13-9]){1}[0-9]{1}(?:[\s.-]?\d{2}){3}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'NL':
|
||||
// https://regex101.com/r/mX2wJ2/1
|
||||
value = $.trim(value);
|
||||
isValid = (/(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/).test(value);
|
||||
break;
|
||||
|
||||
case 'PK':
|
||||
// http://regex101.com/r/yH8aV9/2
|
||||
value = $.trim(value);
|
||||
isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'RO':
|
||||
// All mobile network and land line
|
||||
// http://regexr.com/39fv1
|
||||
isValid = (/^(\+4|)?(07[0-8]{1}[0-9]{1}|02[0-9]{2}|03[0-9]{2}){1}?(\s|\.|\-)?([0-9]{3}(\s|\.|\-|)){2}$/g).test(value);
|
||||
break;
|
||||
|
||||
case 'RU':
|
||||
// http://regex101.com/r/gW7yT5/5
|
||||
isValid = (/^((8|\+7|007)[\-\.\/ ]?)?([\(\/\.]?\d{3}[\)\/\.]?[\-\.\/ ]?)?[\d\-\.\/ ]{7,10}$/g).test(value);
|
||||
break;
|
||||
|
||||
case 'SK':
|
||||
// Test: http://regexr.com/39hhl
|
||||
isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'TH':
|
||||
// http://regex101.com/r/vM5mZ4/2
|
||||
isValid = (/^0\(?([6|8-9]{2})*-([0-9]{3})*-([0-9]{4})$/).test(value);
|
||||
break;
|
||||
|
||||
case 'VE':
|
||||
// http://regex101.com/r/eM2yY0/6
|
||||
value = $.trim(value);
|
||||
isValid = (/^0(?:2(?:12|4[0-9]|5[1-9]|6[0-9]|7[0-8]|8[1-35-8]|9[1-5]|3[45789])|4(?:1[246]|2[46]))\d{7}$/).test(value);
|
||||
break;
|
||||
|
||||
case 'US':
|
||||
/* falls through */
|
||||
default:
|
||||
// Make sure US phone numbers have 10 digits
|
||||
// May start with 1, +1, or 1-; should discard
|
||||
// Area code may be delimited with (), & sections may be delimited with . or -
|
||||
// Test: http://regexr.com/38mqi
|
||||
isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
valid: isValid,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].phone.country, FormValidation.I18n[locale].phone.countries[country])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.phone;
|
||||
}));
|
||||
70
static/src/js/lib/formValidation/validator/regexp.js
Executable file
70
static/src/js/lib/formValidation/validator/regexp.js
Executable file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* regexp validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/regexp/
|
||||
* @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/regexp", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
regexp: {
|
||||
'default': 'Please enter a value matching the pattern'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.regexp = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
regexp: 'regexp'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
var pattern = $field.attr('pattern');
|
||||
if (pattern) {
|
||||
return {
|
||||
regexp: pattern
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the element value matches given regular expression
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - regexp: The regular expression you need to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'regexp');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
|
||||
return regexp.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.regexp;
|
||||
}));
|
||||
146
static/src/js/lib/formValidation/validator/remote.js
Executable file
146
static/src/js/lib/formValidation/validator/remote.js
Executable file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* remote validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/remote/
|
||||
* @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/remote", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
remote: {
|
||||
'default': 'Please enter a valid value'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.remote = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
name: 'name',
|
||||
type: 'type',
|
||||
url: 'url',
|
||||
data: 'data',
|
||||
delay: 'delay'
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroy the timer when destroying the bootstrapValidator (using validator.destroy() method)
|
||||
*/
|
||||
destroy: function(validator, $field, options) {
|
||||
var ns = validator.getNamespace(),
|
||||
timer = $field.data(ns + '.remote.timer');
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
$field.removeData(ns + '.remote.timer');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Request a remote server to check the input value
|
||||
*
|
||||
* @param {FormValidation.Base} validator Plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - url {String|Function}
|
||||
* - type {String} [optional] Can be GET or POST (default)
|
||||
* - data {Object|Function} [optional]: By default, it will take the value
|
||||
* {
|
||||
* <fieldName>: <fieldValue>
|
||||
* }
|
||||
* - delay
|
||||
* - name {String} [optional]: Override the field name for the request.
|
||||
* - message: The invalid message
|
||||
* - headers: Additional headers
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var ns = validator.getNamespace(),
|
||||
value = validator.getFieldValue($field, 'remote'),
|
||||
dfd = new $.Deferred();
|
||||
if (value === '') {
|
||||
dfd.resolve($field, 'remote', { valid: true });
|
||||
return dfd;
|
||||
}
|
||||
|
||||
var name = $field.attr('data-' + ns + '-field'),
|
||||
data = options.data || {},
|
||||
url = options.url,
|
||||
type = options.type || 'GET',
|
||||
headers = options.headers || {};
|
||||
|
||||
// Support dynamic data
|
||||
if ('function' === typeof data) {
|
||||
data = data.call(this, validator);
|
||||
}
|
||||
|
||||
// Parse string data from HTML5 attribute
|
||||
if ('string' === typeof data) {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
|
||||
// Support dynamic url
|
||||
if ('function' === typeof url) {
|
||||
url = url.call(this, validator);
|
||||
}
|
||||
|
||||
data[options.name || name] = value;
|
||||
function runCallback() {
|
||||
var xhr = $.ajax({
|
||||
type: type,
|
||||
headers: headers,
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
data: data
|
||||
});
|
||||
|
||||
xhr
|
||||
.success(function(response) {
|
||||
response.valid = response.valid === true || response.valid === 'true';
|
||||
dfd.resolve($field, 'remote', response);
|
||||
})
|
||||
.error(function(response) {
|
||||
dfd.resolve($field, 'remote', {
|
||||
valid: false
|
||||
});
|
||||
});
|
||||
|
||||
dfd.fail(function() {
|
||||
xhr.abort();
|
||||
});
|
||||
|
||||
return dfd;
|
||||
}
|
||||
|
||||
if (options.delay) {
|
||||
// Since the form might have multiple fields with the same name
|
||||
// I have to attach the timer to the field element
|
||||
if ($field.data(ns + '.remote.timer')) {
|
||||
clearTimeout($field.data(ns + '.remote.timer'));
|
||||
}
|
||||
|
||||
$field.data(ns + '.remote.timer', setTimeout(runCallback, options.delay));
|
||||
return dfd;
|
||||
} else {
|
||||
return runCallback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.remote;
|
||||
}));
|
||||
66
static/src/js/lib/formValidation/validator/rtn.js
Executable file
66
static/src/js/lib/formValidation/validator/rtn.js
Executable file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* rtn validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/rtn/
|
||||
* @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/rtn", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
rtn: {
|
||||
'default': 'Please enter a valid RTN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.rtn = {
|
||||
/**
|
||||
* Validate a RTN (Routing transit number)
|
||||
* Examples:
|
||||
* - Valid: 021200025, 789456124
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/Routing_transit_number
|
||||
* @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, 'rtn');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!/^\d{9}$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
for (var i = 0; i < value.length; i += 3) {
|
||||
sum += parseInt(value.charAt(i), 10) * 3
|
||||
+ parseInt(value.charAt(i + 1), 10) * 7
|
||||
+ parseInt(value.charAt(i + 2), 10);
|
||||
}
|
||||
return (sum !== 0 && sum % 10 === 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.rtn;
|
||||
}));
|
||||
68
static/src/js/lib/formValidation/validator/sedol.js
Executable file
68
static/src/js/lib/formValidation/validator/sedol.js
Executable file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* sedol validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/sedol/
|
||||
* @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/sedol", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
sedol: {
|
||||
'default': 'Please enter a valid SEDOL number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.sedol = {
|
||||
/**
|
||||
* Validate a SEDOL (Stock Exchange Daily Official List)
|
||||
* Examples:
|
||||
* - Valid: 0263494, B0WNLY7
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/SEDOL
|
||||
* @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, 'sedol');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
value = value.toUpperCase();
|
||||
if (!/^[0-9A-Z]{7}$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var sum = 0,
|
||||
weight = [1, 3, 1, 7, 3, 9, 1],
|
||||
length = value.length;
|
||||
for (var i = 0; i < length - 1; i++) {
|
||||
sum += weight[i] * parseInt(value.charAt(i), 36);
|
||||
}
|
||||
sum = (10 - sum % 10) % 10;
|
||||
return sum + '' === value.charAt(length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.sedol;
|
||||
}));
|
||||
56
static/src/js/lib/formValidation/validator/siren.js
Executable file
56
static/src/js/lib/formValidation/validator/siren.js
Executable file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* siren validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/siren/
|
||||
* @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/siren", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
siren: {
|
||||
'default': 'Please enter a valid SIREN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.siren = {
|
||||
/**
|
||||
* Check if a string is a siren 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, 'siren');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!/^\d{9}$/.test(value)) {
|
||||
return false;
|
||||
}
|
||||
return FormValidation.Helper.luhn(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.siren;
|
||||
}));
|
||||
66
static/src/js/lib/formValidation/validator/siret.js
Executable file
66
static/src/js/lib/formValidation/validator/siret.js
Executable file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* siret validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/siret/
|
||||
* @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/siret", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
siret: {
|
||||
'default': 'Please enter a valid SIRET number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.siret = {
|
||||
/**
|
||||
* Check if a string is a siret 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, 'siret');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var sum = 0,
|
||||
length = value.length,
|
||||
tmp;
|
||||
for (var i = 0; i < length; i++) {
|
||||
tmp = parseInt(value.charAt(i), 10);
|
||||
if ((i % 2) === 0) {
|
||||
tmp = tmp * 2;
|
||||
if (tmp > 9) {
|
||||
tmp -= 9;
|
||||
}
|
||||
}
|
||||
sum += tmp;
|
||||
}
|
||||
return (sum % 10 === 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.siret;
|
||||
}));
|
||||
93
static/src/js/lib/formValidation/validator/step.js
Executable file
93
static/src/js/lib/formValidation/validator/step.js
Executable file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* step validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/step/
|
||||
* @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/step", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
step: {
|
||||
'default': 'Please enter a valid step of %s'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.step = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
base: 'baseValue',
|
||||
step: 'step'
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is valid step one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Can consist of the following keys:
|
||||
* - baseValue: The base value
|
||||
* - step: The step
|
||||
* - message: The invalid message
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'step');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
options = $.extend({}, { baseValue: 0, step: 1 }, options);
|
||||
value = parseFloat(value);
|
||||
if (!$.isNumeric(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var round = function(x, precision) {
|
||||
var m = Math.pow(10, precision);
|
||||
x = x * m;
|
||||
var sign = (x > 0) | -(x < 0),
|
||||
isHalf = (x % 1 === 0.5 * sign);
|
||||
if (isHalf) {
|
||||
return (Math.floor(x) + (sign > 0)) / m;
|
||||
} else {
|
||||
return Math.round(x) / m;
|
||||
}
|
||||
},
|
||||
floatMod = function(x, y) {
|
||||
if (y === 0.0) {
|
||||
return 1.0;
|
||||
}
|
||||
var dotX = (x + '').split('.'),
|
||||
dotY = (y + '').split('.'),
|
||||
precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
|
||||
return round(x - y * Math.floor(x / y), precision);
|
||||
};
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
mod = floatMod(value - options.baseValue, options.step);
|
||||
return {
|
||||
valid: mod === 0.0 || mod === options.step,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].step['default'], [options.step])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.step;
|
||||
}));
|
||||
65
static/src/js/lib/formValidation/validator/stringCase.js
Executable file
65
static/src/js/lib/formValidation/validator/stringCase.js
Executable file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* stringCase validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/stringCase/
|
||||
* @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/stringCase", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
stringCase: {
|
||||
'default': 'Please enter only lowercase characters',
|
||||
upper: 'Please enter only uppercase characters'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.stringCase = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
'case': 'case'
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a string is a lower or upper case one
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consist of key:
|
||||
* - message: The invalid message
|
||||
* - case: Can be 'lower' (default) or 'upper'
|
||||
* @returns {Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'stringCase');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
stringCase = (options['case'] || 'lower').toLowerCase();
|
||||
return {
|
||||
valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
|
||||
message: options.message || (('upper' === stringCase) ? FormValidation.I18n[locale].stringCase.upper : FormValidation.I18n[locale].stringCase['default'])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.stringCase;
|
||||
}));
|
||||
140
static/src/js/lib/formValidation/validator/stringLength.js
Executable file
140
static/src/js/lib/formValidation/validator/stringLength.js
Executable file
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* stringLength validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/stringLength/
|
||||
* @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/stringLength", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
stringLength: {
|
||||
'default': 'Please enter a value with valid length',
|
||||
less: 'Please enter less than %s characters',
|
||||
more: 'Please enter more than %s characters',
|
||||
between: 'Please enter value between %s and %s characters long'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.stringLength = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
min: 'min',
|
||||
max: 'max',
|
||||
trim: 'trim',
|
||||
utf8bytes: 'utf8Bytes'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
var options = {},
|
||||
maxLength = $field.attr('maxlength'),
|
||||
minLength = $field.attr('minlength');
|
||||
if (maxLength) {
|
||||
options.max = parseInt(maxLength, 10);
|
||||
}
|
||||
if (minLength) {
|
||||
options.min = parseInt(minLength, 10);
|
||||
}
|
||||
|
||||
return $.isEmptyObject(options) ? false : options;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the length of element value is less or more than given number
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of following keys:
|
||||
* - min
|
||||
* - max
|
||||
* At least one of two keys is required
|
||||
* The min, max keys define the number which the field value compares to. min, max can be
|
||||
* - A number
|
||||
* - Name of field which its value defines the number
|
||||
* - Name of callback function that returns the number
|
||||
* - A callback function that returns the number
|
||||
*
|
||||
* - message: The invalid message
|
||||
* - trim: Indicate the length will be calculated after trimming the value or not. It is false, by default
|
||||
* - utf8bytes: Evaluate string length in UTF-8 bytes, default to false
|
||||
* @returns {Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'stringLength');
|
||||
if (options.trim === true || options.trim === 'true') {
|
||||
value = $.trim(value);
|
||||
}
|
||||
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
|
||||
max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
|
||||
// Credit to http://stackoverflow.com/a/23329386 (@lovasoa) for UTF-8 byte length code
|
||||
utf8Length = function(str) {
|
||||
var s = str.length;
|
||||
for (var i = str.length - 1; i >= 0; i--) {
|
||||
var code = str.charCodeAt(i);
|
||||
if (code > 0x7f && code <= 0x7ff) {
|
||||
s++;
|
||||
} else if (code > 0x7ff && code <= 0xffff) {
|
||||
s += 2;
|
||||
}
|
||||
if (code >= 0xDC00 && code <= 0xDFFF) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
},
|
||||
length = options.utf8Bytes ? utf8Length(value) : value.length,
|
||||
isValid = true,
|
||||
message = options.message || FormValidation.I18n[locale].stringLength['default'];
|
||||
|
||||
if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case (!!min && !!max):
|
||||
message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
|
||||
break;
|
||||
|
||||
case (!!min):
|
||||
message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.more, parseInt(min, 10));
|
||||
break;
|
||||
|
||||
case (!!max):
|
||||
message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.less, parseInt(max, 10));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
valid: isValid,
|
||||
message: message
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.stringLength;
|
||||
}));
|
||||
144
static/src/js/lib/formValidation/validator/uri.js
Executable file
144
static/src/js/lib/formValidation/validator/uri.js
Executable file
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* uri validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/uri/
|
||||
* @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/uri", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
uri: {
|
||||
'default': 'Please enter a valid URI'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.uri = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
allowlocal: 'allowLocal',
|
||||
allowemptyprotocol: 'allowEmptyProtocol',
|
||||
protocol: 'protocol'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
return ('url' === $field.attr('type'));
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if the input value is a valid URL
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options
|
||||
* - message: The error message
|
||||
* - allowLocal: Allow the private and local network IP. Default to false
|
||||
* - allowEmptyProtocol: Allow the URI without protocol. Default to false
|
||||
* - protocol: The protocols, separated by a comma. Default to "http, https, ftp"
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'uri');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Credit to https://gist.github.com/dperini/729294
|
||||
//
|
||||
// Regular Expression for URL validation
|
||||
//
|
||||
// Author: Diego Perini
|
||||
// Updated: 2010/12/05
|
||||
//
|
||||
// the regular expression composed & commented
|
||||
// could be easily tweaked for RFC compliance,
|
||||
// it was expressly modified to fit & satisfy
|
||||
// these test for an URL shortener:
|
||||
//
|
||||
// http://mathiasbynens.be/demo/url-regex
|
||||
//
|
||||
// Notes on possible differences from a standard/generic validation:
|
||||
//
|
||||
// - utf-8 char class take in consideration the full Unicode range
|
||||
// - TLDs are mandatory unless `allowLocal` is true
|
||||
// - protocols have been restricted to ftp, http and https only as requested
|
||||
//
|
||||
// Changes:
|
||||
//
|
||||
// - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
|
||||
// first and last IP address of each class is considered invalid
|
||||
// (since they are broadcast/network addresses)
|
||||
//
|
||||
// - Added exclusion of private, reserved and/or local networks ranges
|
||||
// unless `allowLocal` is true
|
||||
//
|
||||
// - Added possibility of choosing a custom protocol
|
||||
//
|
||||
// - Add option to validate without protocol
|
||||
//
|
||||
var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
|
||||
allowEmptyProtocol = options.allowEmptyProtocol === true || options.allowEmptyProtocol === 'true',
|
||||
protocol = (options.protocol || 'http, https, ftp').split(',').join('|').replace(/\s/g, ''),
|
||||
urlExp = new RegExp(
|
||||
"^" +
|
||||
// protocol identifier
|
||||
"(?:(?:" + protocol + ")://)" +
|
||||
// allow empty protocol
|
||||
(allowEmptyProtocol ? '?' : '') +
|
||||
// user:pass authentication
|
||||
"(?:\\S+(?::\\S*)?@)?" +
|
||||
"(?:" +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
(allowLocal
|
||||
? ''
|
||||
: ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
|
||||
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
|
||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broadcast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||
"|" +
|
||||
// host name
|
||||
"(?:(?:[a-z\\u00a1-\\uffff0-9]-?)*[a-z\\u00a1-\\uffff0-9]+)" +
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-?)*[a-z\\u00a1-\\uffff0-9])*" +
|
||||
// TLD identifier
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
||||
// Allow intranet sites (no TLD) if `allowLocal` is true
|
||||
(allowLocal ? '?' : '') +
|
||||
")" +
|
||||
// port number
|
||||
"(?::\\d{2,5})?" +
|
||||
// resource path
|
||||
"(?:/[^\\s]*)?" +
|
||||
"$", "i"
|
||||
);
|
||||
|
||||
return urlExp.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.uri;
|
||||
}));
|
||||
75
static/src/js/lib/formValidation/validator/uuid.js
Executable file
75
static/src/js/lib/formValidation/validator/uuid.js
Executable file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* uuid validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/uuid/
|
||||
* @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/uuid", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
uuid: {
|
||||
'default': 'Please enter a valid UUID number',
|
||||
version: 'Please enter a valid UUID version %s number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.uuid = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
version: 'version'
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if and only if the input value is a valid UUID string
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/Universally_unique_identifier
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consist of key:
|
||||
* - message: The invalid message
|
||||
* - version: Can be 3, 4, 5, null
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'uuid');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
|
||||
var locale = validator.getLocale(),
|
||||
patterns = {
|
||||
'3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
||||
'4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
||||
'5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
||||
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
|
||||
},
|
||||
version = options.version ? (options.version + '') : 'all';
|
||||
return {
|
||||
valid: (null === patterns[version]) ? true : patterns[version].test(value),
|
||||
message: options.version
|
||||
? FormValidation.Helper.format(options.message || FormValidation.I18n[locale].uuid.version, options.version)
|
||||
: (options.message || FormValidation.I18n[locale].uuid['default'])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.uuid;
|
||||
}));
|
||||
1445
static/src/js/lib/formValidation/validator/vat.js
Executable file
1445
static/src/js/lib/formValidation/validator/vat.js
Executable file
File diff suppressed because it is too large
Load Diff
77
static/src/js/lib/formValidation/validator/vin.js
Executable file
77
static/src/js/lib/formValidation/validator/vin.js
Executable file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* vin validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/vin/
|
||||
* @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/vin", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
vin: {
|
||||
'default': 'Please enter a valid VIN number'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.vin = {
|
||||
/**
|
||||
* Validate an US VIN (Vehicle Identification 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, 'vin');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't accept I, O, Q characters
|
||||
if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
value = value.toUpperCase();
|
||||
var chars = {
|
||||
A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
|
||||
J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
|
||||
S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
|
||||
'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
|
||||
},
|
||||
weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
|
||||
sum = 0,
|
||||
length = value.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
sum += chars[value.charAt(i) + ''] * weights[i];
|
||||
}
|
||||
|
||||
var reminder = sum % 11;
|
||||
if (reminder === 10) {
|
||||
reminder = 'X';
|
||||
}
|
||||
|
||||
return (reminder + '') === value.charAt(8);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.vin;
|
||||
}));
|
||||
269
static/src/js/lib/formValidation/validator/zipCode.js
Executable file
269
static/src/js/lib/formValidation/validator/zipCode.js
Executable file
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
* zipCode validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/zipCode/
|
||||
* @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/zipCode", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
zipCode: {
|
||||
'default': 'Please enter a valid postal code',
|
||||
country: 'Please enter a valid postal code in %s',
|
||||
countries: {
|
||||
AT: 'Austria',
|
||||
BG: 'Bulgaria',
|
||||
BR: 'Brazil',
|
||||
CA: 'Canada',
|
||||
CH: 'Switzerland',
|
||||
CZ: 'Czech Republic',
|
||||
DE: 'Germany',
|
||||
DK: 'Denmark',
|
||||
ES: 'Spain',
|
||||
FR: 'France',
|
||||
GB: 'United Kingdom',
|
||||
IE: 'Ireland',
|
||||
IN: 'India',
|
||||
IT: 'Italy',
|
||||
MA: 'Morocco',
|
||||
NL: 'Netherlands',
|
||||
PT: 'Portugal',
|
||||
RO: 'Romania',
|
||||
RU: 'Russia',
|
||||
SE: 'Sweden',
|
||||
SG: 'Singapore',
|
||||
SK: 'Slovakia',
|
||||
US: 'USA'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.zipCode = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
country: 'country'
|
||||
},
|
||||
|
||||
COUNTRY_CODES: ['AT', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'IE', 'IN', 'IT', 'MA', 'NL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
|
||||
|
||||
/**
|
||||
* Return true if and only if the input value is a valid country zip code
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consist of key:
|
||||
* - message: The invalid message
|
||||
* - country: The country
|
||||
*
|
||||
* The country can be defined by:
|
||||
* - An ISO 3166 country code
|
||||
* - Name of field which its value defines the country code
|
||||
* - Name of callback function that returns the country code
|
||||
* - A callback function that returns the country code
|
||||
*
|
||||
* callback: function(value, validator, $field) {
|
||||
* // value is the value of field
|
||||
* // validator is the BootstrapValidator instance
|
||||
* // $field is jQuery element representing the field
|
||||
* }
|
||||
*
|
||||
* @returns {Boolean|Object}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'zipCode');
|
||||
if (value === '' || !options.country) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var locale = validator.getLocale(),
|
||||
country = options.country;
|
||||
if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
|
||||
// Try to determine the country
|
||||
country = validator.getDynamicOption($field, country);
|
||||
}
|
||||
|
||||
if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var isValid = false;
|
||||
country = country.toUpperCase();
|
||||
switch (country) {
|
||||
// http://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria
|
||||
case 'AT':
|
||||
isValid = /^([1-9]{1})(\d{3})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'BG':
|
||||
isValid = /^([1-9]{1}[0-9]{3})$/.test($.trim(value));
|
||||
break;
|
||||
|
||||
case 'BR':
|
||||
isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'CA':
|
||||
isValid = /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}[0-9]{1}$/i.test(value);
|
||||
break;
|
||||
|
||||
case 'CH':
|
||||
isValid = /^([1-9]{1})(\d{3})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'CZ':
|
||||
// Test: http://regexr.com/39hhr
|
||||
isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
|
||||
break;
|
||||
|
||||
// http://stackoverflow.com/questions/7926687/regular-expression-german-zip-codes
|
||||
case 'DE':
|
||||
isValid = /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'DK':
|
||||
isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
|
||||
break;
|
||||
|
||||
// Zip codes in Spain go from 01XXX to 52XXX.
|
||||
// Test: http://refiddle.com/1ufo
|
||||
case 'ES':
|
||||
isValid = /^(?:0[1-9]|[1-4][0-9]|5[0-2])\d{3}$/.test(value);
|
||||
break;
|
||||
|
||||
// http://en.wikipedia.org/wiki/Postal_codes_in_France
|
||||
case 'FR':
|
||||
isValid = /^[0-9]{5}$/i.test(value);
|
||||
break;
|
||||
|
||||
case 'GB':
|
||||
isValid = this._gb(value);
|
||||
break;
|
||||
|
||||
// Indian PIN (Postal Index Number) validation
|
||||
// http://en.wikipedia.org/wiki/Postal_Index_Number
|
||||
// Test: http://regex101.com/r/kV0vH3/1
|
||||
case 'IN':
|
||||
isValid = /^\d{3}\s?\d{3}$/.test(value);
|
||||
break;
|
||||
|
||||
// http://www.eircode.ie/docs/default-source/Common/prepare-your-business-for-eircode---published-v2.pdf?sfvrsn=2
|
||||
// Test: http://refiddle.com/1kpl
|
||||
case 'IE':
|
||||
isValid = /^(D6W|[ACDEFHKNPRTVWXY]\d{2})\s[0-9ACDEFHKNPRTVWXY]{4}$/.test(value);
|
||||
break;
|
||||
|
||||
// http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
|
||||
case 'IT':
|
||||
isValid = /^(I-|IT-)?\d{5}$/i.test(value);
|
||||
break;
|
||||
|
||||
// http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
|
||||
case 'MA':
|
||||
isValid = /^[1-9][0-9]{4}$/i.test(value);
|
||||
break;
|
||||
|
||||
// http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
|
||||
case 'NL':
|
||||
isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
|
||||
break;
|
||||
|
||||
// Test: http://refiddle.com/1l2t
|
||||
case 'PT':
|
||||
isValid = /^[1-9]\d{3}-\d{3}$/.test(value);
|
||||
break;
|
||||
|
||||
case 'RO':
|
||||
isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
|
||||
break;
|
||||
|
||||
case 'RU':
|
||||
isValid = /^[0-9]{6}$/i.test(value);
|
||||
break;
|
||||
|
||||
case 'SE':
|
||||
isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
|
||||
break;
|
||||
|
||||
case 'SG':
|
||||
isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
|
||||
break;
|
||||
|
||||
case 'SK':
|
||||
// Test: http://regexr.com/39hhr
|
||||
isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
|
||||
break;
|
||||
|
||||
case 'US':
|
||||
/* falls through */
|
||||
default:
|
||||
isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
valid: isValid,
|
||||
message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].zipCode.country, FormValidation.I18n[locale].zipCode.countries[country])
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Validate United Kingdom postcode
|
||||
* Examples:
|
||||
* - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
|
||||
* - Special cases:
|
||||
* AI-2640, ASCN 1ZZ, GIR 0AA
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
|
||||
* @param {String} value The postcode
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
_gb: function(value) {
|
||||
var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
|
||||
secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
|
||||
thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
|
||||
fourthChar = '[ABEHMNPRVWXY]',
|
||||
fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
|
||||
regexps = [
|
||||
// AN NAA, ANN NAA, AAN NAA, AANN NAA format
|
||||
new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
|
||||
// ANA NAA
|
||||
new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
|
||||
// AANA NAA
|
||||
new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
|
||||
|
||||
new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
|
||||
/^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
|
||||
/^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
|
||||
/^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
|
||||
/^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
|
||||
/^(AI-2640)$/i // Anguilla
|
||||
];
|
||||
for (var i = 0; i < regexps.length; i++) {
|
||||
if (regexps[i].test(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.zipCode;
|
||||
}));
|
||||
Reference in New Issue
Block a user