自动排除了 lib,导致js 不全

This commit is contained in:
virusdefender 2015-08-02 12:21:12 +08:00
parent 477fc68ae2
commit 4fb0bd7945
77 changed files with 45609 additions and 1 deletions

1
.gitignore vendored
View File

@ -11,7 +11,6 @@ build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/

File diff suppressed because it is too large Load Diff

2363
static/src/js/lib/bootstrap/bootstrap.js vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,590 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["_code_mirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineMode("clike", function(config, parserConfig) {
var indentUnit = config.indentUnit,
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
dontAlignCalls = parserConfig.dontAlignCalls,
keywords = parserConfig.keywords || {},
types = parserConfig.types || {},
builtin = parserConfig.builtin || {},
blockKeywords = parserConfig.blockKeywords || {},
defKeywords = parserConfig.defKeywords || {},
atoms = parserConfig.atoms || {},
hooks = parserConfig.hooks || {},
multiLineStrings = parserConfig.multiLineStrings,
indentStatements = parserConfig.indentStatements !== false,
indentSwitch = parserConfig.indentSwitch !== false,
namespaceSeparator = parserConfig.namespaceSeparator;
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
var curPunc, isDefKeyword;
function tokenBase(stream, state) {
var ch = stream.next();
if (hooks[ch]) {
var result = hooks[ch](stream, state);
if (result !== false) return result;
}
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
curPunc = ch;
return null;
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
return "number";
}
if (ch == "/") {
if (stream.eat("*")) {
state.tokenize = tokenComment;
return tokenComment(stream, state);
}
if (stream.eat("/")) {
stream.skipToEnd();
return "comment";
}
}
if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return "operator";
}
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
if (namespaceSeparator) while (stream.match(namespaceSeparator))
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
var cur = stream.current();
if (keywords.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
if (defKeywords.propertyIsEnumerable(cur)) isDefKeyword = true;
return "keyword";
}
if (types.propertyIsEnumerable(cur)) return "variable-3";
if (builtin.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "builtin";
}
if (atoms.propertyIsEnumerable(cur)) return "atom";
return "variable";
}
function tokenString(quote) {
return function(stream, state) {
var escaped = false, next, end = false;
while ((next = stream.next()) != null) {
if (next == quote && !escaped) {end = true; break;}
escaped = !escaped && next == "\\";
}
if (end || !(escaped || multiLineStrings))
state.tokenize = null;
return "string";
};
}
function tokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = null;
break;
}
maybeEnd = (ch == "*");
}
return "comment";
}
function Context(indented, column, type, align, prev) {
this.indented = indented;
this.column = column;
this.type = type;
this.align = align;
this.prev = prev;
}
function isStatement(context) {
return context.type == "statement" || context.type == "switchstatement" || context.type == "namespace";
}
function pushContext(state, col, type) {
var indent = state.indented;
if (state.context && isStatement(state.context))
indent = state.context.indented;
return state.context = new Context(indent, col, type, null, state.context);
}
function popContext(state) {
var t = state.context.type;
if (t == ")" || t == "]" || t == "}")
state.indented = state.context.indented;
return state.context = state.context.prev;
}
function typeBefore(stream, state) {
if (state.prevToken == "variable" || state.prevToken == "variable-3") return true;
if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, stream.start))) return true;
}
function isTopScope(context) {
for (;;) {
if (!context || context.type == "top") return true;
if (context.type == "}" && context.prev.type != "namespace") return false;
context = context.prev;
}
}
// Interface
return {
startState: function(basecolumn) {
return {
tokenize: null,
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
indented: 0,
startOfLine: true,
prevToken: null
};
},
token: function(stream, state) {
var ctx = state.context;
if (stream.sol()) {
if (ctx.align == null) ctx.align = false;
state.indented = stream.indentation();
state.startOfLine = true;
}
if (stream.eatSpace()) return null;
curPunc = isDefKeyword = null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style == "comment" || style == "meta") return style;
if (ctx.align == null) ctx.align = true;
if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && isStatement(ctx)) popContext(state);
else if (curPunc == "{") pushContext(state, stream.column(), "}");
else if (curPunc == "[") pushContext(state, stream.column(), "]");
else if (curPunc == "(") pushContext(state, stream.column(), ")");
else if (curPunc == "}") {
while (isStatement(ctx)) ctx = popContext(state);
if (ctx.type == "}") ctx = popContext(state);
while (isStatement(ctx)) ctx = popContext(state);
}
else if (curPunc == ctx.type) popContext(state);
else if (indentStatements &&
(((ctx.type == "}" || ctx.type == "top") && curPunc != ";") ||
(isStatement(ctx) && curPunc == "newstatement"))) {
var type = "statement";
if (curPunc == "newstatement" && indentSwitch && stream.current() == "switch")
type = "switchstatement";
else if (style == "keyword" && stream.current() == "namespace")
type = "namespace";
pushContext(state, stream.column(), type);
}
if (style == "variable" &&
((state.prevToken == "def" ||
(parserConfig.typeFirstDefinitions && typeBefore(stream, state) &&
isTopScope(state.context) && stream.match(/^\s*\(/, false)))))
style = "def";
if (hooks.token) {
var result = hooks.token(stream, state, style);
if (result !== undefined) style = result;
}
if (style == "def" && parserConfig.styleDefs === false) style = "variable";
state.startOfLine = false;
state.prevToken = isDefKeyword ? "def" : style || curPunc;
return style;
},
indent: function(state, textAfter) {
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (isStatement(ctx) && firstChar == "}") ctx = ctx.prev;
var closing = firstChar == ctx.type;
var switchBlock = ctx.prev && ctx.prev.type == "switchstatement";
if (isStatement(ctx))
return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
if (ctx.align && (!dontAlignCalls || ctx.type != ")"))
return ctx.column + (closing ? 0 : 1);
if (ctx.type == ")" && !closing)
return ctx.indented + statementIndentUnit;
return ctx.indented + (closing ? 0 : indentUnit) +
(!closing && switchBlock && !/^(?:case|default)\b/.test(textAfter) ? indentUnit : 0);
},
electricInput: indentSwitch ? /^\s*(?:case .*?:|default:|\{\}?|\})$/ : /^\s*[{}]$/,
blockCommentStart: "/*",
blockCommentEnd: "*/",
lineComment: "//",
fold: "brace"
};
});
function words(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}
var cKeywords = "auto if break case register continue return default do sizeof " +
"static else struct switch extern typedef float union for " +
"goto while enum const volatile";
var cTypes = "int long char short double float unsigned signed void size_t ptrdiff_t";
function cppHook(stream, state) {
if (!state.startOfLine) return false;
for (;;) {
if (stream.skipTo("\\")) {
stream.next();
if (stream.eol()) {
state.tokenize = cppHook;
break;
}
} else {
stream.skipToEnd();
state.tokenize = null;
break;
}
}
return "meta";
}
function pointerHook(_stream, state) {
if (state.prevToken == "variable-3") return "variable-3";
return false;
}
function cpp11StringHook(stream, state) {
stream.backUp(1);
// Raw strings.
if (stream.match(/(R|u8R|uR|UR|LR)/)) {
var match = stream.match(/"([^\s\\()]{0,16})\(/);
if (!match) {
return false;
}
state.cpp11RawStringDelim = match[1];
state.tokenize = tokenRawString;
return tokenRawString(stream, state);
}
// Unicode strings/chars.
if (stream.match(/(u8|u|U|L)/)) {
if (stream.match(/["']/, /* eat */ false)) {
return "string";
}
return false;
}
// Ignore this hook.
stream.next();
return false;
}
function cppLooksLikeConstructor(word) {
var lastTwo = /(\w+)::(\w+)$/.exec(word);
return lastTwo && lastTwo[1] == lastTwo[2];
}
// C#-style strings where "" escapes a quote.
function tokenAtString(stream, state) {
var next;
while ((next = stream.next()) != null) {
if (next == '"' && !stream.eat('"')) {
state.tokenize = null;
break;
}
}
return "string";
}
// C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where
// <delim> can be a string up to 16 characters long.
function tokenRawString(stream, state) {
// Escape characters that have special regex meanings.
var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&');
var match = stream.match(new RegExp(".*?\\)" + delim + '"'));
if (match)
state.tokenize = null;
else
stream.skipToEnd();
return "string";
}
function def(mimes, mode) {
if (typeof mimes == "string") mimes = [mimes];
var words = [];
function add(obj) {
if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
words.push(prop);
}
add(mode.keywords);
add(mode.types);
add(mode.builtin);
add(mode.atoms);
if (words.length) {
mode.helperType = mimes[0];
CodeMirror.registerHelper("hintWords", mimes[0], words);
}
for (var i = 0; i < mimes.length; ++i)
CodeMirror.defineMIME(mimes[i], mode);
}
def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
name: "clike",
keywords: words(cKeywords),
types: words(cTypes + " bool _Complex _Bool float_t double_t intptr_t intmax_t " +
"int8_t int16_t int32_t int64_t uintptr_t uintmax_t uint8_t uint16_t " +
"uint32_t uint64_t"),
blockKeywords: words("case do else for if switch while struct"),
defKeywords: words("struct"),
typeFirstDefinitions: true,
atoms: words("null true false"),
hooks: {"#": cppHook, "*": pointerHook},
modeProps: {fold: ["brace", "include"]}
});
def(["text/x-c++src", "text/x-c++hdr"], {
name: "clike",
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try explicit new " +
"static_cast typeid catch operator template typename class friend private " +
"this using const_cast inline public throw virtual delete mutable protected " +
"alignas alignof constexpr decltype nullptr noexcept thread_local final " +
"static_assert override"),
types: words(cTypes + " bool wchar_t"),
blockKeywords: words("catch class do else finally for if struct switch try while"),
defKeywords: words("class namespace struct enum union"),
typeFirstDefinitions: true,
atoms: words("true false null"),
hooks: {
"#": cppHook,
"*": pointerHook,
"u": cpp11StringHook,
"U": cpp11StringHook,
"L": cpp11StringHook,
"R": cpp11StringHook,
token: function(stream, state, style) {
if (style == "variable" && stream.peek() == "(" &&
(state.prevToken == ";" || state.prevToken == null ||
state.prevToken == "}") &&
cppLooksLikeConstructor(stream.current()))
return "def";
}
},
namespaceSeparator: "::",
modeProps: {fold: ["brace", "include"]}
});
def("text/x-java", {
name: "clike",
keywords: words("abstract assert break case catch class const continue default " +
"do else enum extends final finally float for goto if implements import " +
"instanceof interface native new package private protected public " +
"return static strictfp super switch synchronized this throw throws transient " +
"try volatile while"),
types: words("byte short int long float double boolean char void Boolean Byte Character Double Float " +
"Integer Long Number Object Short String StringBuffer StringBuilder Void"),
blockKeywords: words("catch class do else finally for if switch try while"),
defKeywords: words("class interface package enum"),
typeFirstDefinitions: true,
atoms: words("true false null"),
hooks: {
"@": function(stream) {
stream.eatWhile(/[\w\$_]/);
return "meta";
}
},
modeProps: {fold: ["brace", "import"]}
});
def("text/x-csharp", {
name: "clike",
keywords: words("abstract as async await base break case catch checked class const continue" +
" default delegate do else enum event explicit extern finally fixed for" +
" foreach goto if implicit in interface internal is lock namespace new" +
" operator out override params private protected public readonly ref return sealed" +
" sizeof stackalloc static struct switch this throw try typeof unchecked" +
" unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
" global group into join let orderby partial remove select set value var yield"),
types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" +
" Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" +
" UInt64 bool byte char decimal double short int long object" +
" sbyte float string ushort uint ulong"),
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
defKeywords: words("class interface namespace struct var"),
typeFirstDefinitions: true,
atoms: words("true false null"),
hooks: {
"@": function(stream, state) {
if (stream.eat('"')) {
state.tokenize = tokenAtString;
return tokenAtString(stream, state);
}
stream.eatWhile(/[\w\$_]/);
return "meta";
}
}
});
function tokenTripleString(stream, state) {
var escaped = false;
while (!stream.eol()) {
if (!escaped && stream.match('"""')) {
state.tokenize = null;
break;
}
escaped = stream.next() == "\\" && !escaped;
}
return "string";
}
def("text/x-scala", {
name: "clike",
keywords: words(
/* scala */
"abstract case catch class def do else extends false final finally for forSome if " +
"implicit import lazy match new null object override package private protected return " +
"sealed super this throw trait try type val var while with yield _ : = => <- <: " +
"<% >: # @ " +
/* package scala */
"assert assume require print println printf readLine readBoolean readByte readShort " +
"readChar readInt readLong readFloat readDouble " +
":: #:: "
),
types: words(
"AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
"Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
"Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
"Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
"StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector " +
/* package java.lang */
"Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
"Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
"Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
"StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
),
multiLineStrings: true,
blockKeywords: words("catch class do else finally for forSome if match switch try while"),
defKeywords: words("class def object package trait type val var"),
atoms: words("true false null"),
indentStatements: false,
indentSwitch: false,
hooks: {
"@": function(stream) {
stream.eatWhile(/[\w\$_]/);
return "meta";
},
'"': function(stream, state) {
if (!stream.match('""')) return false;
state.tokenize = tokenTripleString;
return state.tokenize(stream, state);
},
"'": function(stream) {
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
return "atom";
}
},
modeProps: {closeBrackets: {triples: '"'}}
});
def(["x-shader/x-vertex", "x-shader/x-fragment"], {
name: "clike",
keywords: words("sampler1D sampler2D sampler3D samplerCube " +
"sampler1DShadow sampler2DShadow " +
"const attribute uniform varying " +
"break continue discard return " +
"for while do if else struct " +
"in out inout"),
types: words("float int bool void " +
"vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
"mat2 mat3 mat4"),
blockKeywords: words("for while do if else struct"),
builtin: words("radians degrees sin cos tan asin acos atan " +
"pow exp log exp2 sqrt inversesqrt " +
"abs sign floor ceil fract mod min max clamp mix step smoothstep " +
"length distance dot cross normalize ftransform faceforward " +
"reflect refract matrixCompMult " +
"lessThan lessThanEqual greaterThan greaterThanEqual " +
"equal notEqual any all not " +
"texture1D texture1DProj texture1DLod texture1DProjLod " +
"texture2D texture2DProj texture2DLod texture2DProjLod " +
"texture3D texture3DProj texture3DLod texture3DProjLod " +
"textureCube textureCubeLod " +
"shadow1D shadow2D shadow1DProj shadow2DProj " +
"shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
"dFdx dFdy fwidth " +
"noise1 noise2 noise3 noise4"),
atoms: words("true false " +
"gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
"gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
"gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
"gl_FogCoord gl_PointCoord " +
"gl_Position gl_PointSize gl_ClipVertex " +
"gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
"gl_TexCoord gl_FogFragCoord " +
"gl_FragCoord gl_FrontFacing " +
"gl_FragData gl_FragDepth " +
"gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
"gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
"gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
"gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
"gl_ProjectionMatrixInverseTranspose " +
"gl_ModelViewProjectionMatrixInverseTranspose " +
"gl_TextureMatrixInverseTranspose " +
"gl_NormalScale gl_DepthRange gl_ClipPlane " +
"gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
"gl_FrontLightModelProduct gl_BackLightModelProduct " +
"gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
"gl_FogParameters " +
"gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
"gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
"gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
"gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
"gl_MaxDrawBuffers"),
indentSwitch: false,
hooks: {"#": cppHook},
modeProps: {fold: ["brace", "include"]}
});
def("text/x-nesc", {
name: "clike",
keywords: words(cKeywords + "as atomic async call command component components configuration event generic " +
"implementation includes interface module new norace nx_struct nx_union post provides " +
"signal task uses abstract extends"),
types: words(cTypes),
blockKeywords: words("case do else for if switch while struct"),
atoms: words("null true false"),
hooks: {"#": cppHook},
modeProps: {fold: ["brace", "include"]}
});
def("text/x-objectivec", {
name: "clike",
keywords: words(cKeywords + "inline restrict _Bool _Complex _Imaginery BOOL Class bycopy byref id IMP in " +
"inout nil oneway out Protocol SEL self super atomic nonatomic retain copy readwrite readonly"),
types: words(cTypes),
atoms: words("YES NO NULL NILL ON OFF true false"),
hooks: {
"@": function(stream) {
stream.eatWhile(/[\w\$]/);
return "keyword";
},
"#": cppHook
},
modeProps: {fold: "brace"}
});
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
/**
* Simplified Chinese translation for bootstrap-datetimepicker
* Yuan Cheung <advanimal@gmail.com>
*/
;(function($){
$.fn.datetimepicker.dates['zh-CN'] = {
days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
today: "今天",
suffix: [],
meridiem: ["上午", "下午"]
};
}(jQuery));

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
/**
* !!!!!! dev-version and still in progress !!!!!!!
* this plugin loads all required components
* to start validaton process properly
* How to use this:
* include bsfvalidator according to the following pattern
* bsfvalidator!LANG:VALIDATORS
*
* Options:
* LANG - (optinal and single value) indicates which language will be used
* VALIDATORS - (required) defines which validators should be used
* Examples:
* 1) bsfvalidator!ua_UA:notEmpty,stringLength,regexp,emailAddress
* 2) bsfvalidator!notEmpty,stringLength,regexp,emailAddress
* 3) bsfvalidator!notEmpty
* There is simple requirejs based project in demo/amd folder
*/
define("bsfvalidator", ["base", "helper", "framework/bootstrap"], function (base) {
var buildMap = [];
function getDeps (name) {
var parts = name.match(/((.*):)?(.*)/),
lang = null,
deps = [],
all = [];
if (parts.length === 4) {
lang = parts[2];
deps = parts[3].split(',');
}
if (parts.length === 3) {
deps = parts[2].split(',');
}
for (var i = 0, len = deps.length; i < len; i++) {
deps[i] = './validator/' + deps[i];
}
if (lang) {
lang = './language/' + lang;
all.push(lang);
}
all = all.concat(deps);
return {
lang: lang,
deps: deps,
all: all
};
}
return {
load: function (name, req, onLoad, config) {
var deps = getDeps(name);
req(deps.all, function () {
onLoad(base);
});
}
}
});

View File

@ -0,0 +1,294 @@
/**
* FormValidation (http://formvalidation.io)
* The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
*
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
/**
* This class supports validating Bootstrap form (http://getbootstrap.com/)
*/
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("framework/bootstrap", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
FormValidation.Framework.Bootstrap = function(element, options, namespace) {
options = $.extend(true, {
button: {
selector: '[type="submit"]',
// The class of disabled button
// http://getbootstrap.com/css/#buttons-disabled
disabled: 'disabled'
},
err: {
// http://getbootstrap.com/css/#forms-help-text
clazz: 'help-block',
parent: '^(.*)col-(xs|sm|md|lg)-(offset-){0,1}[0-9]+(.*)$'
},
// This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
// Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
// In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
//
// Examples:
// - Use Glyphicons icons:
// icon: {
// valid: 'glyphicon glyphicon-ok',
// invalid: 'glyphicon glyphicon-remove',
// validating: 'glyphicon glyphicon-refresh',
// feedback: 'form-control-feedback'
// }
// - Use FontAwesome icons:
// icon: {
// valid: 'fa fa-check',
// invalid: 'fa fa-times',
// validating: 'fa fa-refresh',
// feedback: 'form-control-feedback'
// }
icon: {
valid: null,
invalid: null,
validating: null,
feedback: 'form-control-feedback'
},
row: {
// By default, each field is placed inside the <div class="form-group"></div>
// http://getbootstrap.com/css/#forms
selector: '.form-group',
valid: 'has-success',
invalid: 'has-error',
feedback: 'has-feedback'
}
}, options);
FormValidation.Base.apply(this, [element, options, namespace]);
};
FormValidation.Framework.Bootstrap.prototype = $.extend({}, FormValidation.Base.prototype, {
/**
* Specific framework might need to adjust the icon position
*
* @param {jQuery} $field The field element
* @param {jQuery} $icon The icon element
*/
_fixIcon: function($field, $icon) {
var ns = this._namespace,
type = $field.attr('type'),
field = $field.attr('data-' + ns + '-field'),
row = this.options.fields[field].row || this.options.row.selector,
$parent = $field.closest(row);
// Place it after the container of checkbox/radio
// so when clicking the icon, it doesn't effect to the checkbox/radio element
if ('checkbox' === type || 'radio' === type) {
var $fieldParent = $field.parent();
if ($fieldParent.hasClass(type)) {
$icon.insertAfter($fieldParent);
} else if ($fieldParent.parent().hasClass(type)) {
$icon.insertAfter($fieldParent.parent());
}
}
// The feedback icon does not render correctly if there is no label
// https://github.com/twbs/bootstrap/issues/12873
if ($parent.find('label').length === 0) {
$icon.addClass('fv-icon-no-label');
}
// Fix feedback icons in input-group
if ($parent.find('.input-group').length !== 0) {
$icon.addClass('fv-bootstrap-icon-input-group')
.insertAfter($parent.find('.input-group').eq(0));
}
},
/**
* Create a tooltip or popover
* It will be shown when focusing on the field
*
* @param {jQuery} $field The field element
* @param {String} message The message
* @param {String} type Can be 'tooltip' or 'popover'
*/
_createTooltip: function($field, message, type) {
var ns = this._namespace,
$icon = $field.data(ns + '.icon');
if ($icon) {
switch (type) {
case 'popover':
$icon
.css({
'cursor': 'pointer',
'pointer-events': 'auto'
})
.popover('destroy')
.popover({
container: 'body',
content: message,
html: true,
placement: 'auto top',
trigger: 'hover click'
});
break;
case 'tooltip':
/* falls through */
default:
$icon
.css({
'cursor': 'pointer',
'pointer-events': 'auto'
})
.tooltip('destroy')
.tooltip({
container: 'body',
html: true,
placement: 'auto top',
title: message
});
break;
}
}
},
/**
* Destroy the tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_destroyTooltip: function($field, type) {
var ns = this._namespace,
$icon = $field.data(ns + '.icon');
if ($icon) {
switch (type) {
case 'popover':
$icon
.css({
'cursor': '',
'pointer-events': 'none'
})
.popover('destroy');
break;
case 'tooltip':
/* falls through */
default:
$icon
.css({
'cursor': '',
'pointer-events': 'none'
})
.tooltip('destroy');
break;
}
}
},
/**
* Hide a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_hideTooltip: function($field, type) {
var ns = this._namespace,
$icon = $field.data(ns + '.icon');
if ($icon) {
switch (type) {
case 'popover':
$icon.popover('hide');
break;
case 'tooltip':
/* falls through */
default:
$icon.tooltip('hide');
break;
}
}
},
/**
* Show a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_showTooltip: function($field, type) {
var ns = this._namespace,
$icon = $field.data(ns + '.icon');
if ($icon) {
switch (type) {
case 'popover':
$icon.popover('show');
break;
case 'tooltip':
/* falls through */
default:
$icon.tooltip('show');
break;
}
}
}
});
/**
* Plugin definition
* Support backward
* @deprecated It will be removed soon. Instead of using $(form).bootstrapValidator(), use
* $(form).formValidation({
* framework: 'bootstrap' // It's equivalent to use data-fv-framework="bootstrap" for <form>
* });
*/
$.fn.bootstrapValidator = function(option) {
var params = arguments;
return this.each(function() {
var $this = $(this),
data = $this.data('formValidation') || $this.data('bootstrapValidator'),
options = 'object' === typeof option && option;
if (!data) {
data = new FormValidation.Framework.Bootstrap(this, $.extend({}, {
events: {
// Support backward
formInit: 'init.form.bv',
formError: 'error.form.bv',
formSuccess: 'success.form.bv',
fieldAdded: 'added.field.bv',
fieldRemoved: 'removed.field.bv',
fieldInit: 'init.field.bv',
fieldError: 'error.field.bv',
fieldSuccess: 'success.field.bv',
fieldStatus: 'status.field.bv',
localeChanged: 'changed.locale.bv',
validatorError: 'error.validator.bv',
validatorSuccess: 'success.validator.bv'
}
}, options), 'bv');
$this.addClass('fv-form-bootstrap')
.data('formValidation', data)
.data('bootstrapValidator', data);
}
// Allow to call plugin method
if ('string' === typeof option) {
data[option].apply(data, Array.prototype.slice.call(params, 1));
}
});
};
$.fn.bootstrapValidator.Constructor = FormValidation.Framework.Bootstrap;
return FormValidation.Framework.Bootstrap;
}));

View File

@ -0,0 +1,177 @@
/**
* FormValidation (http://formvalidation.io)
* The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
*
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
/**
* This class supports validating Foundation form (http://foundation.zurb.com/)
*/
/* global Foundation: false */
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("framework/foundation", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
FormValidation.Framework.Foundation = function(element, options) {
options = $.extend(true, {
button: {
selector: '[type="submit"]',
// The class for disabled button
// http://foundation.zurb.com/docs/components/buttons.html#button-colors
disabled: 'disabled'
},
err: {
// http://foundation.zurb.com/docs/components/forms.html#error-states
clazz: 'error',
parent: '^.*((small|medium|large)-[0-9]+)\\s.*(columns).*$'
},
// Foundation doesn't support feedback icon
icon: {
valid: null,
invalid: null,
validating: null,
feedback: 'fv-control-feedback'
},
row: {
// http://foundation.zurb.com/docs/components/forms.html
selector: '.row',
valid: 'fv-has-success',
invalid: 'error',
feedback: 'fv-has-feedback'
}
}, options);
FormValidation.Base.apply(this, [element, options]);
};
FormValidation.Framework.Foundation.prototype = $.extend({}, FormValidation.Base.prototype, {
/**
* Specific framework might need to adjust the icon position
*
* @param {jQuery} $field The field element
* @param {jQuery} $icon The icon element
*/
_fixIcon: function($field, $icon) {
var ns = this._namespace,
type = $field.attr('type'),
field = $field.attr('data-' + ns + '-field'),
row = this.options.fields[field].row || this.options.row.selector,
$parent = $field.closest(row);
if ('checkbox' === type || 'radio' === type) {
var $next = $icon.next();
if ($next.is('label')) {
$icon.insertAfter($next);
}
}
if ($parent.find('label').length === 0) {
$icon.addClass('fv-icon-no-label');
}
},
/**
* Create a tooltip or popover
* It will be shown when focusing on the field
*
* @param {jQuery} $field The field element
* @param {String} message The message
* @param {String} type Can be 'tooltip' or 'popover'
*/
_createTooltip: function($field, message, type) {
var that = this,
$icon = $field.data('fv.icon');
if ($icon) {
$icon
.attr('title', message)
.css({
'cursor': 'pointer'
})
.off('mouseenter.container.fv focusin.container.fv')
.on('mouseenter.container.fv', function() {
that._showTooltip($field, type);
})
.off('mouseleave.container.fv focusout.container.fv')
.on('mouseleave.container.fv focusout.container.fv', function() {
that._hideTooltip($field, type);
});
Foundation.libs.tooltip.create($icon);
$icon.data('fv.foundation.tooltip', $icon);
}
},
/**
* Destroy the tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_destroyTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
$icon.css({
'cursor': ''
});
var $tooltip = $icon.data('fv.foundation.tooltip');
if ($tooltip) {
// Foundation doesn't provide method to destroy particular tooltip instance
$tooltip.off('.fndtn.tooltip');
Foundation.libs.tooltip.hide($tooltip);
$icon.removeData('fv.foundation.tooltip');
}
}
},
/**
* Hide a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_hideTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
$icon.css({
'cursor': ''
});
var $tooltip = $icon.data('fv.foundation.tooltip');
if ($tooltip) {
Foundation.libs.tooltip.hide($tooltip);
}
}
},
/**
* Show a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_showTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
var $tooltip = $icon.data('fv.foundation.tooltip');
if ($tooltip) {
$icon.css({
'cursor': 'pointer'
});
Foundation.libs.tooltip.show($tooltip);
}
}
}
});
return FormValidation.Framework.Foundation;
}));

View File

@ -0,0 +1,78 @@
/**
* FormValidation (http://formvalidation.io)
* The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
*
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
/**
* This class supports validating Pure framework (http://purecss.io/)
*/
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("framework/pure", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
FormValidation.Framework.Pure = function(element, options) {
options = $.extend(true, {
button: {
selector: '[type="submit"]',
// The class of disabled button
// http://purecss.io/buttons/#disabled-buttons
disabled: 'pure-button-disabled'
},
err: {
clazz: 'fv-help-block',
parent: '^.*pure-control-group.*$'
},
// Pure doesn't support feedback icon
icon: {
valid: null,
invalid: null,
validating: null,
feedback: 'fv-control-feedback'
},
row: {
// http://purecss.io/forms/#aligned-form
selector: '.pure-control-group',
valid: 'fv-has-success',
invalid: 'fv-has-error',
feedback: 'fv-has-feedback'
}
}, options);
FormValidation.Base.apply(this, [element, options]);
};
FormValidation.Framework.Pure.prototype = $.extend({}, FormValidation.Base.prototype, {
/**
* Specific framework might need to adjust the icon position
*
* @param {jQuery} $field The field element
* @param {jQuery} $icon The icon element
*/
_fixIcon: function($field, $icon) {
var ns = this._namespace,
type = $field.attr('type'),
field = $field.attr('data-' + ns + '-field'),
row = this.options.fields[field].row || this.options.row.selector,
$parent = $field.closest(row);
if ($parent.find('label').length === 0) {
$icon.addClass('fv-icon-no-label');
}
}
});
return FormValidation.Framework.Pure;
}));

View File

@ -0,0 +1,177 @@
/**
* FormValidation (http://formvalidation.io)
* The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
*
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
/**
* This class supports validating SemanticUI form (http://semantic-ui.com/)
*/
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("framework/semantic", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
FormValidation.Framework.Semantic = function(element, options) {
options = $.extend(true, {
button: {
selector: '[type="submit"]',
// CSS class of disabled button
// http://semantic-ui.com/elements/button.html#disabled
disabled: 'disabled'
},
control: {
valid: '',
invalid: ''
},
err: {
// http://semantic-ui.com/elements/label.html#pointing
clazz: 'ui red pointing label transition',
parent: '^.*(field|column).*$'
},
// When using feedback icon, the input must place inside 'ui input icon' element
// <div class="ui input icon">
// <input type="text" />
// </div>
// See http://semantic-ui.com/elements/input.html#icon
icon: {
// http://semantic-ui.com/elements/icon.html
valid: null, // 'checkmark icon'
invalid: null, // 'remove icon'
validating: null, // 'refresh icon'
feedback: 'fv-control-feedback'
},
row: {
// http://semantic-ui.com/collections/form.html
selector: '.field',
valid: 'fv-has-success',
invalid: 'error',
feedback: 'fv-has-feedback'
}
}, options);
FormValidation.Base.apply(this, [element, options]);
};
FormValidation.Framework.Semantic.prototype = $.extend({}, FormValidation.Base.prototype, {
/**
* Specific framework might need to adjust the icon position
*
* @param {jQuery} $field The field element
* @param {jQuery} $icon The icon element
*/
_fixIcon: function($field, $icon) {
var type = $field.attr('type');
if ('checkbox' === type || 'radio' === type) {
var $fieldParent = $field.parent();
if ($fieldParent.hasClass(type)) {
$icon.insertAfter($fieldParent);
}
}
},
/**
* Create a tooltip or popover
* It will be shown when focusing on the field
*
* @param {jQuery} $field The field element
* @param {String} message The message
* @param {String} type Can be 'tooltip' or 'popover'
*/
_createTooltip: function($field, message, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
// Remove the popup if it's already exists
if ($icon.popup('exists')) {
$icon.popup('remove popup')
.popup('destroy');
}
// http://semantic-ui.com/modules/popup.html
switch (type) {
case 'popover':
$icon
.css({
'cursor': 'pointer'
})
.popup({
content: message,
position: 'top center'
});
break;
case 'tooltip':
/* falls through */
default:
$icon
.css({
'cursor': 'pointer'
})
.popup({
content: message,
position: 'top center',
variation: 'inverted'
});
break;
}
}
},
/**
* Destroy the tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_destroyTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon && $icon.popup('exists')) {
$icon
.css({
'cursor': ''
})
.popup('remove popup')
.popup('destroy');
}
},
/**
* Hide a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_hideTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
$icon.popup('hide');
}
},
/**
* Show a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_showTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
$icon.popup('show');
}
}
});
return FormValidation.Framework.Semantic;
}));

View File

@ -0,0 +1,179 @@
/**
* FormValidation (http://formvalidation.io)
* The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
*
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
/**
* This class supports validating UIKit form (http://getuikit.com/)
*/
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("framework/uikit", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
FormValidation.Framework.UIKit = function(element, options) {
options = $.extend(true, {
button: {
selector: '[type="submit"]',
// The class for disabled button
// http://getuikit.com/docs/button.html
disabled: 'disabled'
},
control: {
valid: 'uk-form-success',
invalid: 'uk-form-danger'
},
err: {
// http://getuikit.com/docs/text.html#text-styles
clazz: 'uk-text-danger',
parent: '^.*(uk-form-controls|uk-width-[\\d+]-[\\d+]).*$'
},
// UIKit doesn't support feedback icon
icon: {
valid: null,
invalid: null,
validating: null,
feedback: 'fv-control-feedback'
},
row: {
// http://getuikit.com/docs/form.html
selector: '.uk-form-row',
valid: 'fv-has-success',
invalid: 'fv-has-error',
feedback: 'fv-has-feedback'
}
}, options);
FormValidation.Base.apply(this, [element, options]);
};
FormValidation.Framework.UIKit.prototype = $.extend({}, FormValidation.Base.prototype, {
/**
* Specific framework might need to adjust the icon position
*
* @param {jQuery} $field The field element
* @param {jQuery} $icon The icon element
*/
_fixIcon: function($field, $icon) {
var ns = this._namespace,
type = $field.attr('type'),
field = $field.attr('data-' + ns + '-field'),
row = this.options.fields[field].row || this.options.row.selector,
$parent = $field.closest(row);
if ('checkbox' === type || 'radio' === type) {
var $fieldParent = $field.parent();
if ($fieldParent.is('label')) {
$icon.insertAfter($fieldParent);
}
}
if ($parent.find('label').length === 0) {
$icon.addClass('fv-icon-no-label');
}
},
/**
* Create a tooltip or popover
* It will be shown when focusing on the field
*
* @param {jQuery} $field The field element
* @param {String} message The message
* @param {String} type Can be 'tooltip' or 'popover'
*/
_createTooltip: function($field, message, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
// Remove the tooltip if it's already exists
if ($icon.data('tooltip')) {
$icon.data('tooltip').off();
$icon.removeData('tooltip');
}
$icon
.attr('title', message)
.css({
'cursor': 'pointer'
});
new $.UIkit.tooltip($icon);
// UIKit auto set the 'tooltip' data for the element
// so I can retrieve the tooltip later via $icon.data('tooltip')
}
},
/**
* Destroy the tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_destroyTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
var tooltip = $icon.data('tooltip');
if (tooltip) {
tooltip.hide();
tooltip.off();
$icon.off('focus mouseenter')
.removeData('tooltip');
}
$icon.css({
'cursor': ''
});
}
},
/**
* Hide a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_hideTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
var tooltip = $icon.data('tooltip');
if (tooltip) {
tooltip.hide();
}
$icon.css({
'cursor': ''
});
}
},
/**
* Show a tooltip or popover
*
* @param {jQuery} $field The field element
* @param {String} type Can be 'tooltip' or 'popover'
*/
_showTooltip: function($field, type) {
var $icon = $field.data('fv.icon');
if ($icon) {
$icon.css({
'cursor': 'pointer'
});
var tooltip = $icon.data('tooltip');
if (tooltip) {
tooltip.show();
}
}
}
});
return FormValidation.Framework.UIKit;
}));

View File

@ -0,0 +1,181 @@
/**
* FormValidation (http://formvalidation.io)
* The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
*
* @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("helper", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
// Helper methods, which can be used in validator class
FormValidation.Helper = {
/**
* Execute a callback function
*
* @param {String|Function} functionName Can be
* - name of global function
* - name of namespace function (such as A.B.C)
* - a function
* @param {Array} args The callback arguments
*/
call: function(functionName, args) {
if ('function' === typeof functionName) {
return functionName.apply(this, args);
} else if ('string' === typeof functionName) {
if ('()' === functionName.substring(functionName.length - 2)) {
functionName = functionName.substring(0, functionName.length - 2);
}
var ns = functionName.split('.'),
func = ns.pop(),
context = window;
for (var i = 0; i < ns.length; i++) {
context = context[ns[i]];
}
return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
}
},
/**
* Validate a date
*
* @param {Number} year The full year in 4 digits
* @param {Number} month The month number
* @param {Number} day The day number
* @param {Boolean} [notInFuture] If true, the date must not be in the future
* @returns {Boolean}
*/
date: function(year, month, day, notInFuture) {
if (isNaN(year) || isNaN(month) || isNaN(day)) {
return false;
}
if (day.length > 2 || month.length > 2 || year.length > 4) {
return false;
}
day = parseInt(day, 10);
month = parseInt(month, 10);
year = parseInt(year, 10);
if (year < 1000 || year > 9999 || month <= 0 || month > 12) {
return false;
}
var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Update the number of days in Feb of leap year
if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
numDays[1] = 29;
}
// Check the day
if (day <= 0 || day > numDays[month - 1]) {
return false;
}
if (notInFuture === true) {
var currentDate = new Date(),
currentYear = currentDate.getFullYear(),
currentMonth = currentDate.getMonth(),
currentDay = currentDate.getDate();
return (year < currentYear
|| (year === currentYear && month - 1 < currentMonth)
|| (year === currentYear && month - 1 === currentMonth && day < currentDay));
}
return true;
},
/**
* Format a string
* It's used to format the error message
* format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
*
* @param {String} message
* @param {Array} parameters
* @returns {String}
*/
format: function(message, parameters) {
if (!$.isArray(parameters)) {
parameters = [parameters];
}
for (var i in parameters) {
message = message.replace('%s', parameters[i]);
}
return message;
},
/**
* Implement Luhn validation algorithm
* Credit to https://gist.github.com/ShirtlessKirk/2134376
*
* @see http://en.wikipedia.org/wiki/Luhn
* @param {String} value
* @returns {Boolean}
*/
luhn: function(value) {
var length = value.length,
mul = 0,
prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
sum = 0;
while (length--) {
sum += prodArr[mul][parseInt(value.charAt(length), 10)];
mul ^= 1;
}
return (sum % 10 === 0 && sum > 0);
},
/**
* Implement modulus 11, 10 (ISO 7064) algorithm
*
* @param {String} value
* @returns {Boolean}
*/
mod11And10: function(value) {
var check = 5,
length = value.length;
for (var i = 0; i < length; i++) {
check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
}
return (check === 1);
},
/**
* Implements Mod 37, 36 (ISO 7064) algorithm
* Usages:
* mod37And36('A12425GABC1234002M')
* mod37And36('002006673085', '0123456789')
*
* @param {String} value
* @param {String} [alphabet]
* @returns {Boolean}
*/
mod37And36: function(value, alphabet) {
alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var modulus = alphabet.length,
length = value.length,
check = Math.floor(modulus / 2);
for (var i = 0; i < length; i++) {
check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
}
return (check === 1);
}
};
return FormValidation.Helper;
}));

View File

@ -0,0 +1,391 @@
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("language/zh_CN", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
/**
* Simplified Chinese language package
* Translated by @shamiao
*/
FormValidation.I18n = $.extend(true, FormValidation.I18n, {
'zh_CN': {
base64: {
'default': '请输入有效的Base64编码'
},
between: {
'default': '请输入在 %s 和 %s 之间的数值',
notInclusive: '请输入在 %s 和 %s 之间(不含两端)的数值'
},
bic: {
'default': '请输入有效的BIC商品编码'
},
callback: {
'default': '请输入有效的值'
},
choice: {
'default': '请输入有效的值',
less: '请至少选中 %s 个选项',
more: '最多只能选中 %s 个选项',
between: '请选择 %s 至 %s 个选项'
},
color: {
'default': '请输入有效的颜色值'
},
creditCard: {
'default': '请输入有效的信用卡号码'
},
cusip: {
'default': '请输入有效的美国CUSIP代码'
},
cvv: {
'default': '请输入有效的CVV代码'
},
date: {
'default': '请输入有效的日期',
min: '请输入 %s 或之后的日期',
max: '请输入 %s 或以前的日期',
range: '请输入 %s 和 %s 之间的日期'
},
different: {
'default': '请输入不同的值'
},
digits: {
'default': '请输入有效的数字'
},
ean: {
'default': '请输入有效的EAN商品编码'
},
ein: {
'default': '请输入有效的EIN商品编码'
},
emailAddress: {
'default': '请输入有效的邮件地址'
},
file: {
'default': '请选择有效的文件'
},
greaterThan: {
'default': '请输入大于等于 %s 的数值',
notInclusive: '请输入大于 %s 的数值'
},
grid: {
'default': '请输入有效的GRId编码'
},
hex: {
'default': '请输入有效的16进制数'
},
iban: {
'default': '请输入有效的IBAN(国际银行账户)号码',
country: '请输入有效的 %s 国家或地区的IBAN(国际银行账户)号码',
countries: {
AD: '安道​​尔',
AE: '阿联酋',
AL: '阿尔巴尼亚',
AO: '安哥拉',
AT: '奥地利',
AZ: '阿塞拜疆',
BA: '波斯尼亚和黑塞哥维那',
BE: '比利时',
BF: '布基纳法索',
BG: '保加利亚',
BH: '巴林',
BI: '布隆迪',
BJ: '贝宁',
BR: '巴西',
CH: '瑞士',
CI: '科特迪瓦',
CM: '喀麦隆',
CR: '哥斯达黎加',
CV: '佛得角',
CY: '塞浦路斯',
CZ: '捷克共和国',
DE: '德国',
DK: '丹麦',
DO: '多米尼加共和国',
DZ: '阿尔及利亚',
EE: '爱沙尼亚',
ES: '西班牙',
FI: '芬兰',
FO: '法罗群岛',
FR: '法国',
GB: '英国',
GE: '格鲁吉亚',
GI: '直布罗陀',
GL: '格陵兰岛',
GR: '希腊',
GT: '危地马拉',
HR: '克罗地亚',
HU: '匈牙利',
IE: '爱尔兰',
IL: '以色列',
IR: '伊朗',
IS: '冰岛',
IT: '意大利',
JO: '约旦',
KW: '科威特',
KZ: '哈萨克斯坦',
LB: '黎巴嫩',
LI: '列支敦士登',
LT: '立陶宛',
LU: '卢森堡',
LV: '拉脱维亚',
MC: '摩纳哥',
MD: '摩尔多瓦',
ME: '黑山',
MG: '马达加斯加',
MK: '马其顿',
ML: '马里',
MR: '毛里塔尼亚',
MT: '马耳他',
MU: '毛里求斯',
MZ: '莫桑比克',
NL: '荷兰',
NO: '挪威',
PK: '巴基斯坦',
PL: '波兰',
PS: '巴勒斯坦',
PT: '葡萄牙',
QA: '卡塔尔',
RO: '罗马尼亚',
RS: '塞尔维亚',
SA: '沙特阿拉伯',
SE: '瑞典',
SI: '斯洛文尼亚',
SK: '斯洛伐克',
SM: '圣马力诺',
SN: '塞内加尔',
TN: '突尼斯',
TR: '土耳其',
VG: '英属维尔京群岛'
}
},
id: {
'default': '请输入有效的身份证件号码',
country: '请输入有效的 %s 国家或地区的身份证件号码',
countries: {
BA: '波黑',
BG: '保加利亚',
BR: '巴西',
CH: '瑞士',
CL: '智利',
CN: '中国',
CZ: '捷克共和国',
DK: '丹麦',
EE: '爱沙尼亚',
ES: '西班牙',
FI: '芬兰',
HR: '克罗地亚',
IE: '爱尔兰',
IS: '冰岛',
LT: '立陶宛',
LV: '拉脱维亚',
ME: '黑山',
MK: '马其顿',
NL: '荷兰',
RO: '罗马尼亚',
RS: '塞尔维亚',
SE: '瑞典',
SI: '斯洛文尼亚',
SK: '斯洛伐克',
SM: '圣马力诺',
TH: '泰国',
ZA: '南非'
}
},
identical: {
'default': '请输入相同的值'
},
imei: {
'default': '请输入有效的IMEI(手机串号)'
},
imo: {
'default': '请输入有效的国际海事组织(IMO)号码'
},
integer: {
'default': '请输入有效的整数值'
},
ip: {
'default': '请输入有效的IP地址',
ipv4: '请输入有效的IPv4地址',
ipv6: '请输入有效的IPv6地址'
},
isbn: {
'default': '请输入有效的ISBN(国际标准书号)'
},
isin: {
'default': '请输入有效的ISIN(国际证券编码)'
},
ismn: {
'default': '请输入有效的ISMN(印刷音乐作品编码)'
},
issn: {
'default': '请输入有效的ISSN(国际标准杂志书号)'
},
lessThan: {
'default': '请输入小于等于 %s 的数值',
notInclusive: '请输入小于 %s 的数值'
},
mac: {
'default': '请输入有效的MAC物理地址'
},
meid: {
'default': '请输入有效的MEID(移动设备识别码)'
},
notEmpty: {
'default': '请填写必填项目'
},
numeric: {
'default': '请输入有效的数值,允许小数'
},
phone: {
'default': '请输入有效的电话号码',
country: '请输入有效的 %s 国家或地区的电话号码',
countries: {
AE: '阿联酋',
BG: '保加利亚',
BR: '巴西',
CN: '中国',
CZ: '捷克共和国',
DE: '德国',
DK: '丹麦',
ES: '西班牙',
FR: '法国',
GB: '英国',
IN: '印度',
MA: '摩洛哥',
NL: '荷兰',
PK: '巴基斯坦',
RO: '罗马尼亚',
RU: '俄罗斯',
SK: '斯洛伐克',
TH: '泰国',
US: '美国',
VE: '委内瑞拉'
}
},
regexp: {
'default': '请输入符合正则表达式限制的值'
},
remote: {
'default': '请输入有效的值'
},
rtn: {
'default': '请输入有效的RTN号码'
},
sedol: {
'default': '请输入有效的SEDOL代码'
},
siren: {
'default': '请输入有效的SIREN号码'
},
siret: {
'default': '请输入有效的SIRET号码'
},
step: {
'default': '请输入在基础值上,增加 %s 的整数倍的数值'
},
stringCase: {
'default': '只能输入小写字母',
upper: '只能输入大写字母'
},
stringLength: {
'default': '请输入符合长度限制的值',
less: '最多只能输入 %s 个字符',
more: '需要输入至少 %s 个字符',
between: '请输入 %s 至 %s 个字符'
},
uri: {
'default': '请输入一个有效的URL地址'
},
uuid: {
'default': '请输入有效的UUID',
version: '请输入版本 %s 的UUID'
},
vat: {
'default': '请输入有效的VAT(税号)',
country: '请输入有效的 %s 国家或地区的VAT(税号)',
countries: {
AT: '奥地利',
BE: '比利时',
BG: '保加利亚',
BR: '巴西',
CH: '瑞士',
CY: '塞浦路斯',
CZ: '捷克共和国',
DE: '德国',
DK: '丹麦',
EE: '爱沙尼亚',
ES: '西班牙',
FI: '芬兰',
FR: '法语',
GB: '英国',
GR: '希腊',
EL: '希腊',
HU: '匈牙利',
HR: '克罗地亚',
IE: '爱尔兰',
IS: '冰岛',
IT: '意大利',
LT: '立陶宛',
LU: '卢森堡',
LV: '拉脱维亚',
MT: '马耳他',
NL: '荷兰',
NO: '挪威',
PL: '波兰',
PT: '葡萄牙',
RO: '罗马尼亚',
RU: '俄罗斯',
RS: '塞尔维亚',
SE: '瑞典',
SI: '斯洛文尼亚',
SK: '斯洛伐克',
VE: '委内瑞拉',
ZA: '南非'
}
},
vin: {
'default': '请输入有效的VIN(美国车辆识别号码)'
},
zipCode: {
'default': '请输入有效的邮政编码',
country: '请输入有效的 %s 国家或地区的邮政编码',
countries: {
AT: '奥地利',
BG: '保加利亚',
BR: '巴西',
CA: '加拿大',
CH: '瑞士',
CZ: '捷克共和国',
DE: '德国',
DK: '丹麦',
ES: '西班牙',
FR: '法国',
GB: '英国',
IE: '爱尔兰',
IN: '印度',
IT: '意大利',
MA: '摩洛哥',
NL: '荷兰',
PT: '葡萄牙',
RO: '罗马尼亚',
RU: '俄罗斯',
SE: '瑞典',
SG: '新加坡',
SK: '斯洛伐克',
US: '美国'
}
}
}
});
return FormValidation.I18n.zh_CN;
}));

View File

@ -0,0 +1,391 @@
(function(root, factory) {
"use strict";
// AMD module is defined
if (typeof define === "function" && define.amd) {
define("language/zh_TW", ["jquery", "base"], factory);
} else {
// planted over the root!
factory(root.jQuery, root.FormValidation);
}
}(this, function ($, FormValidation) {
/**
* Traditional Chinese language package
* Translated by @tureki
*/
FormValidation.I18n = $.extend(true, FormValidation.I18n, {
'zh_TW': {
base64: {
'default': '請輸入有效的Base64編碼'
},
between: {
'default': '請輸入不小於 %s 且不大於 %s 的值',
notInclusive: '請輸入不小於等於 %s 且不大於等於 %s 的值'
},
bic: {
'default': '請輸入有效的BIC商品編碼'
},
callback: {
'default': '請輸入有效的值'
},
choice: {
'default': '請輸入有效的值',
less: '最少選擇 %s 個選項',
more: '最多選擇 %s 個選項',
between: '請選擇 %s 至 %s 個選項'
},
color: {
'default': '請輸入有效的元色碼'
},
creditCard: {
'default': '請輸入有效的信用卡號碼'
},
cusip: {
'default': '請輸入有效的CUSIP(美國證券庫斯普)號碼'
},
cvv: {
'default': '請輸入有效的CVV(信用卡檢查碼)代碼'
},
date: {
'default': '請輸入有效的日期',
min: '請輸入 %s 或之後的日期',
max: '請輸入 %s 或以前的日期',
range: '請輸入 %s 至 %s 之間的日期'
},
different: {
'default': '請輸入不同的值'
},
digits: {
'default': '只能輸入數字'
},
ean: {
'default': '請輸入有效的EAN商品編碼'
},
ein: {
'default': '請輸入有效的EIN商品編碼'
},
emailAddress: {
'default': '請輸入有效的EMAIL'
},
file: {
'default': '請選擇有效的檔案'
},
greaterThan: {
'default': '請輸入大於等於 %s 的值',
notInclusive: '請輸入大於 %s 的值'
},
grid: {
'default': '請輸入有效的GRId編碼'
},
hex: {
'default': '請輸入有效的16位元碼'
},
iban: {
'default': '請輸入有效的IBAN(國際銀行賬戶)號碼',
country: '請輸入有效的 %s 國家的IBAN(國際銀行賬戶)號碼',
countries: {
AD: '安道​​爾',
AE: '阿聯酋',
AL: '阿爾巴尼亞',
AO: '安哥拉',
AT: '奧地利',
AZ: '阿塞拜疆',
BA: '波斯尼亞和黑塞哥維那',
BE: '比利時',
BF: '布基納法索',
BG: '保加利亞',
BH: '巴林',
BI: '布隆迪',
BJ: '貝寧',
BR: '巴西',
CH: '瑞士',
CI: '象牙海岸',
CM: '喀麥隆',
CR: '哥斯達黎加',
CV: '佛得角',
CY: '塞浦路斯',
CZ: '捷克共和國',
DE: '德國',
DK: '丹麥',
DO: '多明尼加共和國',
DZ: '阿爾及利亞',
EE: '愛沙尼亞',
ES: '西班牙',
FI: '芬蘭',
FO: '法羅群島',
FR: '法國',
GB: '英國',
GE: '格魯吉亞',
GI: '直布羅陀',
GL: '格陵蘭島',
GR: '希臘',
GT: '危地馬拉',
HR: '克羅地亞',
HU: '匈牙利',
IE: '愛爾蘭',
IL: '以色列',
IR: '伊朗',
IS: '冰島',
IT: '意大利',
JO: '約旦',
KW: '科威特',
KZ: '哈薩克斯坦',
LB: '黎巴嫩',
LI: '列支敦士登',
LT: '立陶宛',
LU: '盧森堡',
LV: '拉脫維亞',
MC: '摩納哥',
MD: '摩爾多瓦',
ME: '蒙特內哥羅',
MG: '馬達加斯加',
MK: '馬其頓',
ML: '馬里',
MR: '毛里塔尼亞',
MT: '馬耳他',
MU: '毛里求斯',
MZ: '莫桑比克',
NL: '荷蘭',
NO: '挪威',
PK: '巴基斯坦',
PL: '波蘭',
PS: '巴勒斯坦',
PT: '葡萄牙',
QA: '卡塔爾',
RO: '羅馬尼亞',
RS: '塞爾維亞',
SA: '沙特阿拉伯',
SE: '瑞典',
SI: '斯洛文尼亞',
SK: '斯洛伐克',
SM: '聖馬力諾',
SN: '塞內加爾',
TN: '突尼斯',
TR: '土耳其',
VG: '英屬維爾京群島'
}
},
id: {
'default': '請輸入有效的身份證字號',
country: '請輸入有效的 %s 身份證字號',
countries: {
BA: '波赫',
BG: '保加利亞',
BR: '巴西',
CH: '瑞士',
CL: '智利',
CN: '中國',
CZ: '捷克共和國',
DK: '丹麥',
EE: '愛沙尼亞',
ES: '西班牙',
FI: '芬蘭',
HR: '克羅地亞',
IE: '愛爾蘭',
IS: '冰島',
LT: '立陶宛',
LV: '拉脫維亞',
ME: '蒙特內哥羅',
MK: '馬其頓',
NL: '荷蘭',
RO: '羅馬尼亞',
RS: '塞爾維亞',
SE: '瑞典',
SI: '斯洛文尼亞',
SK: '斯洛伐克',
SM: '聖馬力諾',
TH: '泰國',
ZA: '南非'
}
},
identical: {
'default': '請輸入相同的值'
},
imei: {
'default': '請輸入有效的IMEI(手機序列號)'
},
imo: {
'default': '請輸入有效的國際海事組織(IMO)號碼'
},
integer: {
'default': '請輸入有效的整數'
},
ip: {
'default': '請輸入有效的IP位址',
ipv4: '請輸入有效的IPv4位址',
ipv6: '請輸入有效的IPv6位址'
},
isbn: {
'default': '請輸入有效的ISBN(國際標準書號)'
},
isin: {
'default': '請輸入有效的ISIN(國際證券號碼)'
},
ismn: {
'default': '請輸入有效的ISMN(國際標準音樂編號)'
},
issn: {
'default': '請輸入有效的ISSN(國際標準期刊號)'
},
lessThan: {
'default': '請輸入小於等於 %s 的值',
notInclusive: '請輸入小於 %s 的值'
},
mac: {
'default': '請輸入有效的MAC位址'
},
meid: {
'default': '請輸入有效的MEID(行動設備識別碼)'
},
notEmpty: {
'default': '請填寫必填欄位'
},
numeric: {
'default': '請輸入有效的數字(含浮點數)'
},
phone: {
'default': '請輸入有效的電話號碼',
country: '請輸入有效的 %s 國家的電話號碼',
countries: {
AE: '阿聯酋',
BG: '保加利亞',
BR: '巴西',
CN: '中国',
CZ: '捷克共和國',
DE: '德國',
DK: '丹麥',
ES: '西班牙',
FR: '法國',
GB: '英國',
IN: '印度',
MA: '摩洛哥',
NL: '荷蘭',
PK: '巴基斯坦',
RO: '罗马尼亚',
RU: '俄羅斯',
SK: '斯洛伐克',
TH: '泰國',
US: '美國',
VE: '委内瑞拉'
}
},
regexp: {
'default': '請輸入符合正規表示式所限制的值'
},
remote: {
'default': '請輸入有效的值'
},
rtn: {
'default': '請輸入有效的RTN號碼'
},
sedol: {
'default': '請輸入有效的SEDOL代碼'
},
siren: {
'default': '請輸入有效的SIREN號碼'
},
siret: {
'default': '請輸入有效的SIRET號碼'
},
step: {
'default': '請輸入 %s 的倍數'
},
stringCase: {
'default': '只能輸入小寫字母',
upper: '只能輸入大寫字母'
},
stringLength: {
'default': '請輸入符合長度限制的值',
less: '請輸入小於 %s 個字',
more: '請輸入大於 %s 個字',
between: '請輸入 %s 至 %s 個字'
},
uri: {
'default': '請輸入一個有效的鏈接'
},
uuid: {
'default': '請輸入有效的UUID',
version: '請輸入版本 %s 的UUID'
},
vat: {
'default': '請輸入有效的VAT(增值税)',
country: '請輸入有效的 %s 國家的VAT(增值税)',
countries: {
AT: '奧地利',
BE: '比利時',
BG: '保加利亞',
BR: '巴西',
CH: '瑞士',
CY: '塞浦路斯',
CZ: '捷克共和國',
DE: '德國',
DK: '丹麥',
EE: '愛沙尼亞',
ES: '西班牙',
FI: '芬蘭',
FR: '法語',
GB: '英國',
GR: '希臘',
EL: '希臘',
HU: '匈牙利',
HR: '克羅地亞',
IE: '愛爾蘭',
IS: '冰島',
IT: '意大利',
LT: '立陶宛',
LU: '盧森堡',
LV: '拉脫維亞',
MT: '馬耳他',
NL: '荷蘭',
NO: '挪威',
PL: '波蘭',
PT: '葡萄牙',
RO: '羅馬尼亞',
RU: '俄羅斯',
RS: '塞爾維亞',
SE: '瑞典',
SI: '斯洛文尼亞',
SK: '斯洛伐克',
VE: '委内瑞拉',
ZA: '南非'
}
},
vin: {
'default': '請輸入有效的VIN(車輛識別號碼)'
},
zipCode: {
'default': '請輸入有效的郵政編碼',
country: '請輸入有效的 %s 國家的郵政編碼',
countries: {
AT: '奧地利',
BG: '保加利亞',
BR: '巴西',
CA: '加拿大',
CH: '瑞士',
CZ: '捷克共和國',
DE: '德國',
DK: '丹麥',
ES: '西班牙',
FR: '法國',
GB: '英國',
IE: '愛爾蘭',
IN: '印度',
IT: '意大利',
MA: '摩洛哥',
NL: '荷蘭',
PT: '葡萄牙',
RO: '羅馬尼亞',
RU: '俄羅斯',
SE: '瑞典',
SG: '新加坡',
SK: '斯洛伐克',
US: '美國'
}
}
}
});
return FormValidation.I18n.zh_TW;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

File diff suppressed because it is too large Load Diff

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

View 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;
}));

File diff suppressed because it is too large Load Diff

View 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;
}));

View 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;
}));

6
static/src/js/lib/jquery/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,241 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define('simple-hotkeys', ["jquery","simple-module"], function ($, SimpleModule) {
return (root['hotkeys'] = factory($, SimpleModule));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("jquery"),require("simple-module"));
} else {
root.simple = root.simple || {};
root.simple['hotkeys'] = factory(jQuery,SimpleModule);
}
}(this, function ($, SimpleModule) {
var Hotkeys, hotkeys,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Hotkeys = (function(superClass) {
extend(Hotkeys, superClass);
function Hotkeys() {
return Hotkeys.__super__.constructor.apply(this, arguments);
}
Hotkeys.count = 0;
Hotkeys.keyNameMap = {
8: "Backspace",
9: "Tab",
13: "Enter",
16: "Shift",
17: "Control",
18: "Alt",
19: "Pause",
20: "CapsLock",
27: "Esc",
32: "Spacebar",
33: "PageUp",
34: "PageDown",
35: "End",
36: "Home",
37: "Left",
38: "Up",
39: "Right",
40: "Down",
45: "Insert",
46: "Del",
91: "Meta",
93: "Meta",
48: "0",
49: "1",
50: "2",
51: "3",
52: "4",
53: "5",
54: "6",
55: "7",
56: "8",
57: "9",
65: "A",
66: "B",
67: "C",
68: "D",
69: "E",
70: "F",
71: "G",
72: "H",
73: "I",
74: "J",
75: "K",
76: "L",
77: "M",
78: "N",
79: "O",
80: "P",
81: "Q",
82: "R",
83: "S",
84: "T",
85: "U",
86: "V",
87: "W",
88: "X",
89: "Y",
90: "Z",
96: "0",
97: "1",
98: "2",
99: "3",
100: "4",
101: "5",
102: "6",
103: "7",
104: "8",
105: "9",
106: "Multiply",
107: "Add",
109: "Subtract",
110: "Decimal",
111: "Divide",
112: "F1",
113: "F2",
114: "F3",
115: "F4",
116: "F5",
117: "F6",
118: "F7",
119: "F8",
120: "F9",
121: "F10",
122: "F11",
123: "F12",
124: "F13",
125: "F14",
126: "F15",
127: "F16",
128: "F17",
129: "F18",
130: "F19",
131: "F20",
132: "F21",
133: "F22",
134: "F23",
135: "F24",
59: ";",
61: "=",
186: ";",
187: "=",
188: ",",
190: ".",
191: "/",
192: "`",
219: "[",
220: "\\",
221: "]",
222: "'"
};
Hotkeys.aliases = {
"escape": "esc",
"delete": "del",
"return": "enter",
"ctrl": "control",
"space": "spacebar",
"ins": "insert",
"cmd": "meta",
"command": "meta",
"wins": "meta",
"windows": "meta"
};
Hotkeys.normalize = function(shortcut) {
var i, j, key, keyname, keys, len;
keys = shortcut.toLowerCase().replace(/\s+/gi, "").split("+");
for (i = j = 0, len = keys.length; j < len; i = ++j) {
key = keys[i];
keys[i] = this.aliases[key] || key;
}
keyname = keys.pop();
keys.sort().push(keyname);
return keys.join("_");
};
Hotkeys.prototype.opts = {
el: document
};
Hotkeys.prototype._init = function() {
this.id = ++this.constructor.count;
this._map = {};
this._delegate = typeof this.opts.el === "string" ? document : this.opts.el;
return $(this._delegate).on("keydown.simple-hotkeys-" + this.id, this.opts.el, (function(_this) {
return function(e) {
var ref;
return (ref = _this._getHander(e)) != null ? ref.call(_this, e) : void 0;
};
})(this));
};
Hotkeys.prototype._getHander = function(e) {
var keyname, shortcut;
if (!(keyname = this.constructor.keyNameMap[e.which])) {
return;
}
shortcut = "";
if (e.altKey) {
shortcut += "alt_";
}
if (e.ctrlKey) {
shortcut += "control_";
}
if (e.metaKey) {
shortcut += "meta_";
}
if (e.shiftKey) {
shortcut += "shift_";
}
shortcut += keyname.toLowerCase();
return this._map[shortcut];
};
Hotkeys.prototype.respondTo = function(subject) {
if (typeof subject === 'string') {
return this._map[this.constructor.normalize(subject)] != null;
} else {
return this._getHander(subject) != null;
}
};
Hotkeys.prototype.add = function(shortcut, handler) {
this._map[this.constructor.normalize(shortcut)] = handler;
return this;
};
Hotkeys.prototype.remove = function(shortcut) {
delete this._map[this.constructor.normalize(shortcut)];
return this;
};
Hotkeys.prototype.destroy = function() {
$(this._delegate).off(".simple-hotkeys-" + this.id);
this._map = {};
return this;
};
return Hotkeys;
})(SimpleModule);
hotkeys = function(opts) {
return new Hotkeys(opts);
};
return hotkeys;
}));

View File

@ -0,0 +1,172 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define('simple-module', ["jquery"], function (a0) {
return (root['Module'] = factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("jquery"));
} else {
root['SimpleModule'] = factory(jQuery);
}
}(this, function ($) {
var Module,
slice = [].slice;
Module = (function() {
Module.extend = function(obj) {
var key, ref, val;
if (!((obj != null) && typeof obj === 'object')) {
return;
}
for (key in obj) {
val = obj[key];
if (key !== 'included' && key !== 'extended') {
this[key] = val;
}
}
return (ref = obj.extended) != null ? ref.call(this) : void 0;
};
Module.include = function(obj) {
var key, ref, val;
if (!((obj != null) && typeof obj === 'object')) {
return;
}
for (key in obj) {
val = obj[key];
if (key !== 'included' && key !== 'extended') {
this.prototype[key] = val;
}
}
return (ref = obj.included) != null ? ref.call(this) : void 0;
};
Module.connect = function(cls) {
if (typeof cls !== 'function') {
return;
}
if (!cls.pluginName) {
throw new Error('Module.connect: cannot connect plugin without pluginName');
return;
}
cls.prototype._connected = true;
if (!this._connectedClasses) {
this._connectedClasses = [];
}
this._connectedClasses.push(cls);
if (cls.pluginName) {
return this[cls.pluginName] = cls;
}
};
Module.prototype.opts = {};
function Module(opts) {
var base, cls, i, instance, instances, len, name;
this.opts = $.extend({}, this.opts, opts);
(base = this.constructor)._connectedClasses || (base._connectedClasses = []);
instances = (function() {
var i, len, ref, results;
ref = this.constructor._connectedClasses;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
cls = ref[i];
name = cls.pluginName.charAt(0).toLowerCase() + cls.pluginName.slice(1);
if (cls.prototype._connected) {
cls.prototype._module = this;
}
results.push(this[name] = new cls());
}
return results;
}).call(this);
if (this._connected) {
this.opts = $.extend({}, this.opts, this._module.opts);
} else {
this._init();
for (i = 0, len = instances.length; i < len; i++) {
instance = instances[i];
if (typeof instance._init === "function") {
instance._init();
}
}
}
this.trigger('initialized');
}
Module.prototype._init = function() {};
Module.prototype.on = function() {
var args, ref;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
(ref = $(this)).on.apply(ref, args);
return this;
};
Module.prototype.one = function() {
var args, ref;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
(ref = $(this)).one.apply(ref, args);
return this;
};
Module.prototype.off = function() {
var args, ref;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
(ref = $(this)).off.apply(ref, args);
return this;
};
Module.prototype.trigger = function() {
var args, ref;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
(ref = $(this)).trigger.apply(ref, args);
return this;
};
Module.prototype.triggerHandler = function() {
var args, ref;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return (ref = $(this)).triggerHandler.apply(ref, args);
};
Module.prototype._t = function() {
var args, ref;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return (ref = this.constructor)._t.apply(ref, args);
};
Module._t = function() {
var args, key, ref, result;
key = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
result = ((ref = this.i18n[this.locale]) != null ? ref[key] : void 0) || '';
if (!(args.length > 0)) {
return result;
}
result = result.replace(/([^%]|^)%(?:(\d+)\$)?s/g, function(p0, p, position) {
if (position) {
return p + args[parseInt(position) - 1];
} else {
return p + args.shift();
}
});
return result.replace(/%%s/g, '%s');
};
Module.i18n = {
'zh-CN': {}
};
Module.locale = 'zh-CN';
return Module;
})();
return Module;
}));

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,261 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define('simple-uploader', ["jquery","simple-module"], function ($, SimpleModule) {
return (root['uploader'] = factory($, SimpleModule));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("jquery"),require("simple-module"));
} else {
root.simple = root.simple || {};
root.simple['uploader'] = factory(jQuery,SimpleModule);
}
}(this, function ($, SimpleModule) {
var Uploader, uploader,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Uploader = (function(superClass) {
extend(Uploader, superClass);
function Uploader() {
return Uploader.__super__.constructor.apply(this, arguments);
}
Uploader.count = 0;
Uploader.prototype.opts = {
url: '',
params: null,
fileKey: 'upload_file',
connectionCount: 3
};
Uploader.prototype._init = function() {
this.files = [];
this.queue = [];
this.id = ++Uploader.count;
this.on('uploadcomplete', (function(_this) {
return function(e, file) {
_this.files.splice($.inArray(file, _this.files), 1);
if (_this.queue.length > 0 && _this.files.length < _this.opts.connectionCount) {
return _this.upload(_this.queue.shift());
} else {
return _this.uploading = false;
}
};
})(this));
return $(window).on('beforeunload.uploader-' + this.id, (function(_this) {
return function(e) {
if (!_this.uploading) {
return;
}
e.originalEvent.returnValue = _this._t('leaveConfirm');
return _this._t('leaveConfirm');
};
})(this));
};
Uploader.prototype.generateId = (function() {
var id;
id = 0;
return function() {
return id += 1;
};
})();
Uploader.prototype.upload = function(file, opts) {
var f, i, key, len;
if (opts == null) {
opts = {};
}
if (file == null) {
return;
}
if ($.isArray(file) || file instanceof FileList) {
for (i = 0, len = file.length; i < len; i++) {
f = file[i];
this.upload(f, opts);
}
} else if ($(file).is('input:file')) {
key = $(file).attr('name');
if (key) {
opts.fileKey = key;
}
this.upload($.makeArray($(file)[0].files), opts);
} else if (!file.id || !file.obj) {
file = this.getFile(file);
}
if (!(file && file.obj)) {
return;
}
$.extend(file, opts);
if (this.files.length >= this.opts.connectionCount) {
this.queue.push(file);
return;
}
if (this.triggerHandler('beforeupload', [file]) === false) {
return;
}
this.files.push(file);
this._xhrUpload(file);
return this.uploading = true;
};
Uploader.prototype.getFile = function(fileObj) {
var name, ref, ref1;
if (fileObj instanceof window.File || fileObj instanceof window.Blob) {
name = (ref = fileObj.fileName) != null ? ref : fileObj.name;
} else {
return null;
}
return {
id: this.generateId(),
url: this.opts.url,
params: this.opts.params,
fileKey: this.opts.fileKey,
name: name,
size: (ref1 = fileObj.fileSize) != null ? ref1 : fileObj.size,
ext: name ? name.split('.').pop().toLowerCase() : '',
obj: fileObj
};
};
Uploader.prototype._xhrUpload = function(file) {
var formData, k, ref, v;
formData = new FormData();
formData.append(file.fileKey, file.obj);
formData.append("original_filename", file.name);
if (file.params) {
ref = file.params;
for (k in ref) {
v = ref[k];
formData.append(k, v);
}
}
return file.xhr = $.ajax({
url: file.url,
data: formData,
processData: false,
contentType: false,
type: 'POST',
headers: {
'X-File-Name': encodeURIComponent(file.name)
},
xhr: function() {
var req;
req = $.ajaxSettings.xhr();
if (req) {
req.upload.onprogress = (function(_this) {
return function(e) {
return _this.progress(e);
};
})(this);
}
return req;
},
progress: (function(_this) {
return function(e) {
if (!e.lengthComputable) {
return;
}
return _this.trigger('uploadprogress', [file, e.loaded, e.total]);
};
})(this),
error: (function(_this) {
return function(xhr, status, err) {
return _this.trigger('uploaderror', [file, xhr, status]);
};
})(this),
success: (function(_this) {
return function(result) {
_this.trigger('uploadprogress', [file, file.size, file.size]);
_this.trigger('uploadsuccess', [file, result]);
return $(document).trigger('uploadsuccess', [file, result, _this]);
};
})(this),
complete: (function(_this) {
return function(xhr, status) {
return _this.trigger('uploadcomplete', [file, xhr.responseText]);
};
})(this)
});
};
Uploader.prototype.cancel = function(file) {
var f, i, len, ref;
if (!file.id) {
ref = this.files;
for (i = 0, len = ref.length; i < len; i++) {
f = ref[i];
if (f.id === file * 1) {
file = f;
break;
}
}
}
this.trigger('uploadcancel', [file]);
if (file.xhr) {
file.xhr.abort();
}
return file.xhr = null;
};
Uploader.prototype.readImageFile = function(fileObj, callback) {
var fileReader, img;
if (!$.isFunction(callback)) {
return;
}
img = new Image();
img.onload = function() {
return callback(img);
};
img.onerror = function() {
return callback();
};
if (window.FileReader && FileReader.prototype.readAsDataURL && /^image/.test(fileObj.type)) {
fileReader = new FileReader();
fileReader.onload = function(e) {
return img.src = e.target.result;
};
return fileReader.readAsDataURL(fileObj);
} else {
return callback();
}
};
Uploader.prototype.destroy = function() {
var file, i, len, ref;
this.queue.length = 0;
ref = this.files;
for (i = 0, len = ref.length; i < len; i++) {
file = ref[i];
this.cancel(file);
}
$(window).off('.uploader-' + this.id);
return $(document).off('.uploader-' + this.id);
};
Uploader.i18n = {
'zh-CN': {
leaveConfirm: '正在上传文件,如果离开上传会自动取消'
}
};
Uploader.locale = 'zh-CN';
return Uploader;
})(SimpleModule);
uploader = function(opts) {
return new Uploader(opts);
};
return uploader;
}));

File diff suppressed because it is too large Load Diff