Commit 0083c3ca by 侯昆

Merge branch 'second_demo' of http://gitlab.coralcodes.com:30000/shil0009/cihai into second_demo

# Conflicts:
#	serverside/cihai-pc/src/main/webapp/WEB-INF/jsp/word/character_paraph.jsp
2 parents 5b8a10a9 c7e364d0
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<div class="album"> <div class="album">
<div class="pic" style="background-image:url(${vo.images.get(0).file})"></div> <div class="pic" style="background-image:url(${vo.images.get(0).file})"></div>
</div> </div>
<div class="sub-tip">${vo.word}图册(5)</div> <!-- <div class="sub-tip">${vo.word}图册(5)</div> -->
</div> </div>
</c:if> </c:if>
</div> </div>
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
</div> </div>
</div> </div>
<div class="content"> <div class="content">
<div class="container">
<div class="row"> <div class="row">
<div class="col-xs-17"> <div class="col-xs-17">
<ul class="tab-nav"> <ul class="tab-nav">
...@@ -232,6 +233,7 @@ ...@@ -232,6 +233,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</div> </div>
<footer class="footer-main"> <footer class="footer-main">
<div class="container"> <div class="container">
......
.n-inline-block,
.nice-validator input,
.nice-validator select,
.nice-validator textarea,
.nice-validator [contenteditable],
.msg-wrap,
.n-icon,
.n-msg {
display: inline-block;
*display: inline;
*zoom: 1;
}
.nice-validator .msg-container .msg-box {
display: block;
}
.nice-validator .msg-container .msg-wrap {
position: static;
}
.msg-box {
position: relative;
*zoom: 1;
}
.msg-wrap {
position: relative;
white-space: nowrap;
line-height: 16px;
font-size: 12px;
}
.msg-wrap,
.n-icon,
.n-msg {
vertical-align: top;
}
.msg-box .msg-wrap .n-error,
.msg-box .msg-wrap .n-ok,
.msg-box .msg-wrap .n-tip {
display: block;
background: none;
box-shadow: none;
padding: 3px 2px;
}
.n-arrow {
position: absolute;
overflow: hidden;
}
.n-arrow b,
.n-arrow i {
position: absolute;
left: 0;
top: 0;
border: 0;
margin: 0;
padding: 0;
overflow: hidden;
font-weight: 400;
font-style: normal;
font-size: 12px;
font-family: serif;
line-height: 14px;
_line-height: 15px;
}
.n-arrow i {
text-shadow: none;
}
.n-icon {
width: 16px;
height: 16px;
overflow: hidden;
background-repeat: no-repeat;
}
.n-msg {
display: inline-block;
*display: inline;
*zoom: 1;
margin-left: 1px;
}
.n-error {
color: #c33;
}
.n-ok {
color: #390;
}
.n-tip .n-msg,
.n-loading {
color: #808080;
}
.n-error .n-icon {
background-position: 0 0;
}
.n-ok .n-icon {
background-position: -16px 0;
}
.n-tip .n-icon {
background-position: -32px 0;
}
.n-loading .n-icon {
background: url("images/loading.gif") 0 center no-repeat !important;
}
.n-top,
.n-right,
.n-bottom,
.n-left {
display: inline-block;
*display: inline;
*zoom: 1;
line-height: 0;
vertical-align: top;
outline: 0;
}
.n-top .n-arrow,
.n-bottom .n-arrow {
height: 6px;
width: 12px;
left: 8px;
}
.n-left .n-arrow,
.n-right .n-arrow {
width: 6px;
height: 12px;
top: 6px;
}
.n-top {
vertical-align: top;
}
.n-top .msg-wrap {
margin-bottom: 6px;
}
.n-top .n-arrow {
bottom: -6px;
}
.n-top .n-arrow b {
top: -6px;
}
.n-top .n-arrow i {
top: -7px;
}
.n-bottom {
vertical-align: bottom;
}
.n-bottom .msg-wrap {
margin-top: 6px;
}
.n-bottom .n-arrow {
top: -6px;
}
.n-bottom .n-arrow b {
top: -1px;
}
.n-bottom .n-arrow i {
top: 0;
}
.n-left .msg-wrap {
right: 100%;
margin-right: 6px;
}
.n-left .n-arrow {
right: -6px;
}
.n-left .n-arrow b {
left: -6px;
}
.n-left .n-arrow i {
left: -7px;
}
.n-right .msg-wrap {
margin-left: 6px;
}
.n-right .n-arrow {
left: -6px;
}
.n-right .n-arrow b {
left: 1px;
}
.n-right .n-arrow i {
left: 2px;
}
/*********************
* Themes
*********************/
.n-default .n-left,
.n-default .n-right {
margin-top: 5px;
}
.n-default .n-top .msg-wrap {
bottom: 100%;
}
.n-default .n-bottom .msg-wrap {
top: 100%;
}
.n-default .msg-wrap {
position: absolute;
z-index: 1;
}
.n-default .msg-wrap .n-icon {
background-image: url("images/validator_default.png");
}
.n-default .n-tip .n-icon {
display: none;
}
.n-simple .msg-wrap {
position: absolute;
z-index: 1;
}
.n-simple .msg-wrap .n-icon {
background-image: url("images/validator_simple.png");
}
.n-simple .n-top .msg-wrap {
bottom: 100%;
}
.n-simple .n-bottom .msg-wrap {
top: 100%;
}
.n-simple .n-left,
.n-simple .n-right {
margin-top: 5px;
}
.n-simple .n-bottom .msg-wrap {
margin-top: 3px;
}
.n-simple .n-tip .n-icon {
display: none;
}
.n-yellow .msg-wrap {
position: absolute;
z-index: 1;
padding: 4px 6px;
font-size: 12px;
border: 1px solid transparent;
background-color: #fffcef;
border-color: #ffbb76;
color: #db7c22;
box-shadow: 0 1px 3px #ccc;
border-radius: 2px;
}
.n-yellow .msg-wrap .n-arrow b {
color: #ffbb76;
text-shadow: 0 0 2px #ccc;
}
.n-yellow .msg-wrap .n-arrow i {
color: #fffcef;
}
.n-yellow .msg-wrap .n-icon {
background-image: url("images/validator_simple.png");
}
.n-yellow .n-top .msg-wrap {
bottom: 100%;
}
.n-yellow .n-bottom .msg-wrap {
top: 100%;
}
.n-yellow .n-tip,
.n-yellow .n-ok,
.n-yellow .n-loading {
background-color: #f8fdff;
border-color: #ddd;
color: #333;
box-shadow: 0 1px 3px #ccc;
}
.n-yellow .n-tip .n-arrow b,
.n-yellow .n-ok .n-arrow b,
.n-yellow .n-loading .n-arrow b {
color: #ddd;
text-shadow: 0 0 2px #ccc;
}
.n-yellow .n-tip .n-arrow i,
.n-yellow .n-ok .n-arrow i,
.n-yellow .n-loading .n-arrow i {
color: #f8fdff;
}
/*! nice-validator 1.1.3
* (c) 2012-2017 Jony Zhang <niceue@live.com>, MIT Licensed
* https://github.com/niceue/nice-validator
*/
;(function(factory) {
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(jQuery);
}(function($, undefined) {
"use strict";
var NS = 'validator',
CLS_NS = '.' + NS,
CLS_NS_RULE = '.rule',
CLS_NS_FIELD = '.field',
CLS_NS_FORM = '.form',
CLS_WRAPPER = 'nice-' + NS,
CLS_MSG_BOX = 'msg-box',
ARIA_INVALID = 'aria-invalid',
DATA_RULE = 'data-rule',
DATA_MSG = 'data-msg',
DATA_TIP = 'data-tip',
DATA_OK = 'data-ok',
DATA_TIMELY = 'data-timely',
DATA_TARGET = 'data-target',
DATA_DISPLAY = 'data-display',
DATA_MUST = 'data-must',
NOVALIDATE = 'novalidate',
INPUT_SELECTOR = ':verifiable',
rRules = /(&)?(!)?\b(\w+)(?:\[\s*(.*?\]?)\s*\]|\(\s*(.*?\)?)\s*\))?\s*(;|\|)?/g,
rRule = /(\w+)(?:\[\s*(.*?\]?)\s*\]|\(\s*(.*?\)?)\s*\))?/,
rDisplay = /(?:([^:;\(\[]*):)?(.*)/,
rDoubleBytes = /[^\x00-\xff]/g,
rPos = /top|right|bottom|left/,
rAjaxType = /(?:(cors|jsonp):)?(?:(post|get):)?(.+)/i,
rUnsafe = /[<>'"`\\]|&#x?\d+[A-F]?;?|%3[A-F]/gmi,
noop = $.noop,
proxy = $.proxy,
trim = $.trim,
isFunction = $.isFunction,
isString = function(s) {
return typeof s === 'string';
},
isObject = function(o) {
return o && Object.prototype.toString.call(o) === '[object Object]';
},
isIE = document.documentMode || +(navigator.userAgent.match(/MSIE (\d+)/) && RegExp.$1),
attr = function(el, key, value) {
if (!el || !el.tagName) return null;
if (value !== undefined) {
if (value === null) el.removeAttribute(key);
else el.setAttribute(key, '' + value);
} else {
return el.getAttribute(key);
}
},
novalidateonce,
preinitialized = {},
defaults = {
debug: 0,
theme: 'default',
ignore: '',
focusInvalid: true,
focusCleanup: false,
stopOnError: false,
beforeSubmit: null,
valid: null,
invalid: null,
validation: null,
formClass: 'n-default',
validClass: 'n-valid',
invalidClass: 'n-invalid',
bindClassTo: null
},
fieldDefaults = {
timely: 1,
display: null,
target: null,
ignoreBlank: false,
showOk: true,
// Translate ajax response to validation result
dataFilter: function (data) {
if ( isString(data) || ( isObject(data) && ('error' in data || 'ok' in data) ) ) {
return data;
}
},
msgMaker: function(opt) {
var html;
html = '<span role="alert" class="msg-wrap n-'+ opt.type + '">' + opt.arrow;
if (opt.result) {
$.each(opt.result, function(i, obj){
html += '<span class="n-'+ obj.type +'">' + opt.icon + '<span class="n-msg">' + obj.msg + '</span></span>';
});
} else {
html += opt.icon + '<span class="n-msg">' + opt.msg + '</span>';
}
html += '</span>';
return html;
},
msgWrapper: 'span',
msgArrow: '',
msgIcon: '<span class="n-icon"></span>',
msgClass: 'n-right',
msgStyle: '',
msgShow: null,
msgHide: null
},
themes = {};
/** jQuery Plugin
* @param {Object} options
debug {Boolean} 0 Whether to enable debug mode
timely {Number} 1 Whether to enable timely validation
theme {String} 'default' Theme name
stopOnError {Boolean} false Whether to stop validate when found an error input
focusCleanup {Boolean} false Whether to clean up the field message when focus the field
focusInvalid {Boolean} true Whether to focus the field that is invalid
ignoreBlank {Boolean} false When the field has no value, whether to ignore validation
ignore {jqSelector} '' Ignored fields (Using jQuery selector)
beforeSubmit {Function} Do something before submit form
dataFilter {Function} Convert ajax results
valid {Function} Triggered when the form is valid
invalid {Function} Triggered when the form is invalid
validClass {String} 'n-valid' Add this class name to a valid field
invalidClass {String} 'n-invalid' Add this class name to a invalid field
bindClassTo {jqSelector} ':verifiable' Which element should the className binding to
display {Function} Callback function to get dynamic display
target {Function} Callback function to get dynamic target
msgShow {Function} Trigger this callback when show message
msgHide {Function} Trigger this callback when hide message
msgWrapper {String} 'span' Message wrapper tag name
msgMaker {Function} Callback function to make message HTML
msgArrow {String} Message arrow template
msgIcon {String} Message icon template
msgStyle {String} Custom message css style
msgClass {String} Additional added to the message class names
formClass {String} Additional added to the form class names
messages {Object} Custom messages for the current instance
rules {Object} Custom rules for the current instance
fields {Object} Field validation configuration
{String} key name|#id
{String|Object} value Rule string or an object which can pass more arguments
fields[key][rule] {String} Rule string
fields[key][display] {String|Function}
fields[key][tip] {String} Custom tip message
fields[key][ok] {String} Custom success message
fields[key][msg] {Object} Custom error message
fields[key][msgStyle] {String} Custom message style
fields[key][msgClass] {String} A className which added to message placeholder element
fields[key][msgWrapper] {String} Tag name of the message placeholder element
fields[key][msgMaker] {Function} A function to custom message HTML
fields[key][dataFilter] {Function} A function to convert ajax results
fields[key][valid] {Function} A function triggered when field is valid
fields[key][invalid] {Function} A function triggered when field is invalid
fields[key][must] {Boolean} If set true, we always check the field even has remote checking
fields[key][timely] {Boolean} Whether to enable timely validation
fields[key][target] {jqSelector} Define placement of a message
*/
$.fn.validator = function(options) {
var that = this,
args = arguments;
if (that.is(INPUT_SELECTOR)) return that;
if (!that.is('form')) that = this.find('form');
if (!that.length) that = this;
that.each(function() {
var instance = $(this).data(NS);
if (instance) {
if ( isString(options) ) {
if ( options.charAt(0) === '_' ) return;
instance[options].apply(instance, [].slice.call(args, 1));
}
else if (options) {
instance._reset(true);
instance._init(this, options);
}
} else {
new Validator(this, options);
}
});
return this;
};
// Validate a field, or an area
$.fn.isValid = function(callback, hideMsg) {
var me = _getInstance(this[0]),
hasCallback = isFunction(callback),
ret, opt;
if (!me) return true;
if (!hasCallback && hideMsg === undefined) hideMsg = callback;
me.checkOnly = !!hideMsg;
opt = me.options;
ret = me._multiValidate(
this.is(INPUT_SELECTOR) ? this : this.find(INPUT_SELECTOR),
function(isValid){
if (!isValid && opt.focusInvalid && !me.checkOnly) {
// navigate to the error element
me.$el.find('[' + ARIA_INVALID + ']:first').focus();
}
if (hasCallback) {
if (callback.length) {
callback(isValid);
} else if (isValid) {
callback();
}
}
me.checkOnly = false;
}
);
// If you pass a callback, we maintain the jQuery object chain
return hasCallback ? this : ret;
};
$.extend($.expr.pseudos || $.expr[':'], {
// A faster selector than ":input:not(:submit,:button,:reset,:image,:disabled,[contenteditable])"
verifiable: function(elem) {
var name = elem.nodeName.toLowerCase();
return ( name === 'input' && !({submit: 1, button: 1, reset: 1, image: 1})[elem.type] ||
name === 'select' ||
name === 'textarea' ||
elem.contentEditable === 'true'
) && !elem.disabled;
},
// any value, but not only whitespace
filled: function(elem) {
return !!trim($(elem).val());
}
});
/**
* Creates a new Validator
*
* @class
* @param {Element} element - form element
* @param {Object} options - options for validator
*/
function Validator(element, options) {
var me = this;
if ( !(me instanceof Validator) ) {
return new Validator(element, options);
}
if (Validator.pending) {
$(window).on('validatorready', init);
} else {
init();
}
function init() {
me.$el = $(element);
if (me.$el.length) {
me._init(me.$el[0], options);
}
else if (isString(element)) {
preinitialized[element] = options;
}
}
}
Validator.prototype = {
_init: function(element, options) {
var me = this,
opt, themeOpt, dataOpt;
// Initialization options
if ( isFunction(options) ) {
options = {
valid: options
};
}
options = me._opt = options || {};
dataOpt = attr(element, 'data-'+ NS +'-option');
dataOpt = me._dataOpt = dataOpt && dataOpt.charAt(0) === '{' ? (new Function("return " + dataOpt))() : {};
themeOpt = me._themeOpt = themes[ options.theme || dataOpt.theme || defaults.theme ];
opt = me.options = $.extend({}, defaults, fieldDefaults, themeOpt, me.options, options, dataOpt);
me.rules = new Rules(opt.rules, true);
me.messages = new Messages(opt.messages, true);
me.Field = _createFieldFactory(me);
me.elements = me.elements || {};
me.deferred = {};
me.errors = {};
me.fields = {};
// Initialization fields
me._initFields(opt.fields);
// Initialization events and make a cache
if ( !me.$el.data(NS) ) {
me.$el.data(NS, me).addClass(CLS_WRAPPER +' '+ opt.formClass)
.on('form-submit-validate', function(e, a, $form, opts, veto) {
me.vetoed = veto.veto = !me.isValid;
me.ajaxFormOptions = opts;
})
.on('submit'+ CLS_NS +' validate'+ CLS_NS, proxy(me, '_submit'))
.on('reset'+ CLS_NS, proxy(me, '_reset'))
.on('showmsg'+ CLS_NS, proxy(me, '_showmsg'))
.on('hidemsg'+ CLS_NS, proxy(me, '_hidemsg'))
.on('focusin'+ CLS_NS + ' click'+ CLS_NS, INPUT_SELECTOR, proxy(me, '_focusin'))
.on('focusout'+ CLS_NS +' validate'+ CLS_NS, INPUT_SELECTOR, proxy(me, '_focusout'))
.on('keyup'+ CLS_NS +' input'+ CLS_NS + ' compositionstart compositionend', INPUT_SELECTOR, proxy(me, '_focusout'))
.on('click'+ CLS_NS, ':radio,:checkbox', 'click', proxy(me, '_focusout'))
.on('change'+ CLS_NS, 'select,input[type="file"]', 'change', proxy(me, '_focusout'));
// cache the novalidate attribute value
me._NOVALIDATE = attr(element, NOVALIDATE);
// Initialization is complete, stop off default HTML5 form validation
// If use "jQuery.attr('novalidate')" in IE7 will complain: "SCRIPT3: Member not found."
attr(element, NOVALIDATE, NOVALIDATE);
}
// Display all messages in target container
if ( isString(opt.target) ) {
me.$el.find(opt.target).addClass('msg-container');
}
},
// Guess whether the form use ajax submit
_guessAjax: function(form) {
var me = this;
if ( !(me.isAjaxSubmit = !!me.options.valid) ) {
// if there is a "valid.form" event
var events = ($._data || $.data)(form, "events");
me.isAjaxSubmit = issetEvent(events, 'valid', 'form') || issetEvent(events, 'submit', 'form-plugin');
}
function issetEvent(events, name, namespace) {
if ( events && events[name] &&
$.map(events[name], function(e){
return ~e.namespace.indexOf(namespace) ? 1 : null;
}).length
) {
return true;
}
return false;
}
},
_initFields: function(fields) {
var me = this, k, arr, i,
clear = fields === null;
// Processing field information
if (clear) fields = me.fields;
if ( isObject(fields) ) {
for (k in fields) {
if (~k.indexOf(',')) {
arr = k.split(',');
i = arr.length;
while (i--) {
initField(trim(arr[i]), fields[k]);
}
} else {
initField(k, fields[k]);
}
}
}
// Parsing DOM rules
me.$el.find(INPUT_SELECTOR).each(function() {
me._parse(this);
});
function initField(k, v) {
// delete a field from settings
if ( v === null || clear ) {
var el = me.elements[k];
if (el) me._resetElement(el, true);
delete me.fields[k];
} else {
me.fields[k] = new me.Field(k, isString(v) ? {rule: v} : v, me.fields[k]);
}
}
},
// Parsing a field
_parse: function(el) {
var me = this,
field,
key = el.name,
display,
timely,
dataRule = attr(el, DATA_RULE);
dataRule && attr(el, DATA_RULE, null);
// If the field has passed the key as id mode, or it doesn't has a name
if ( el.id && (
('#' + el.id in me.fields) ||
!key ||
// If dataRule and element are diffrent from old's, we use ID mode.
(dataRule !== null && (field = me.fields[key]) && dataRule !== field.rule && el.id !== field.key)
)
) {
key = '#' + el.id;
}
// Generate id
if (!key) {
key = '#' + (el.id = 'N' + String(Math.random()).slice(-12));
}
field = me.getField(key, true);
// The priority of passing parameter by DOM is higher than by JS.
field.rule = dataRule || field.rule;
if (display = attr(el, DATA_DISPLAY)) {
field.display = display;
}
if (field.rule) {
if ( attr(el, DATA_MUST) !== null || /\b(?:match|checked)\b/.test(field.rule) ) {
field.must = true;
}
if ( /\brequired\b/.test(field.rule) ) {
field.required = true;
}
if (timely = attr(el, DATA_TIMELY)) {
field.timely = +timely;
} else if (field.timely > 3) {
attr(el, DATA_TIMELY, field.timely);
}
me._parseRule(field);
field.old = {};
}
if ( isString(field.target) ) {
attr(el, DATA_TARGET, field.target);
}
if ( isString(field.tip) ) {
attr(el, DATA_TIP, field.tip);
}
return me.fields[key] = field;
},
// Parsing field rules
_parseRule: function(field) {
var arr = rDisplay.exec(field.rule);
if (!arr) return;
// current rule index
field._i = 0;
if (arr[1]) {
field.display = arr[1];
}
if (arr[2]) {
field._rules = [];
arr[2].replace(rRules, function(){
var args = arguments;
args[4] = args[4] || args[5];
field._rules.push({
and: args[1] === "&",
not: args[2] === "!",
or: args[6] === "|",
method: args[3],
params: args[4] ? $.map( args[4].split(', '), trim ) : undefined
});
});
}
},
// Verify a zone
_multiValidate: function($inputs, doneCallback){
var me = this,
opt = me.options;
me.hasError = false;
if (opt.ignore) {
$inputs = $inputs.not(opt.ignore);
}
$inputs.each(function() {
me._validate(this);
if (me.hasError && opt.stopOnError) {
// stop the validation
return false;
}
});
// Need to wait for all fields validation complete, especially asynchronous validation
if (doneCallback) {
me.validating = true;
$.when.apply(
null,
$.map(me.deferred, function(v){return v;})
).done(function(){
doneCallback.call(me, !me.hasError);
me.validating = false;
});
}
// If the form does not contain asynchronous validation, the return value is correct.
// Otherwise, you should detect form validation result through "doneCallback".
return !$.isEmptyObject(me.deferred) ? undefined : !me.hasError;
},
// Validate the whole form
_submit: function(e) {
var me = this,
opt = me.options,
form = e.target,
canSubmit = e.type === 'submit' && form.tagName === 'FORM' && !e.isDefaultPrevented();
e.preventDefault();
if (
novalidateonce && ~(novalidateonce = false) ||
// Prevent duplicate submission
me.submiting ||
// Receive the "validate" event only from the form.
e.type === 'validate' && me.$el[0] !== form ||
// trigger the beforeSubmit callback.
isFunction(opt.beforeSubmit) && opt.beforeSubmit.call(me, form) === false
) {
return;
}
if (me.isAjaxSubmit === undefined) {
me._guessAjax(form);
}
me._debug('log', '\n<<< event: ' + e.type);
me._reset();
me.submiting = true;
me._multiValidate(
me.$el.find(INPUT_SELECTOR),
function(isValid){
var ret = (isValid || opt.debug === 2) ? 'valid' : 'invalid',
errors;
if (!isValid) {
if (opt.focusInvalid) {
// navigate to the error element
me.$el.find('[' + ARIA_INVALID + ']:first').focus();
}
errors = $.map(me.errors, function(err){return err;});
}
// releasing submit
me.submiting = false;
me.isValid = isValid;
// trigger callback and event
isFunction(opt[ret]) && opt[ret].call(me, form, errors);
me.$el.trigger(ret + CLS_NS_FORM, [form, errors]);
me._debug('log', '>>> ' + ret);
if (!isValid) return;
// For jquery.form plugin
if (me.vetoed) {
$(form).ajaxSubmit(me.ajaxFormOptions);
}
else if (canSubmit && !me.isAjaxSubmit) {
document.createElement('form').submit.call(form);
}
}
);
},
_reset: function(e) {
var me = this;
me.errors = {};
if (e) {
me.reseting = true;
me.$el.find(INPUT_SELECTOR).each( function(){
me._resetElement(this);
});
delete me.reseting;
}
},
_resetElement: function(el, all) {
this._setClass(el, null);
this.hideMsg(el);
},
// Handle events: "focusin/click"
_focusin: function(e) {
var me = this,
opt = me.options,
el = e.target,
timely,
msg;
if ( me.validating || ( e.type==='click' && document.activeElement === el ) ) {
return;
}
if (opt.focusCleanup) {
if ( attr(el, ARIA_INVALID) === 'true' ) {
me._setClass(el, null);
me.hideMsg(el);
}
}
msg = attr(el, DATA_TIP);
if (msg) {
me.showMsg(el, {
type: 'tip',
msg: msg
});
} else {
if (attr(el, DATA_RULE)) {
me._parse(el);
}
if (timely = attr(el, DATA_TIMELY)) {
if ( timely === 8 || timely === 9 ) {
me._focusout(e);
}
}
}
},
// Handle events: "focusout/validate/keyup/click/change/input/compositionstart/compositionend"
_focusout: function(e) {
var me = this,
opt = me.options,
el = e.target,
etype = e.type,
etype0,
focusin = etype === 'focusin',
special = etype === 'validate',
elem,
field,
old,
value,
timestamp,
key, specialKey,
timely,
timer = 0;
if (etype === 'compositionstart') {
me.pauseValidate = true;
}
if (etype === 'compositionend') {
me.pauseValidate = false;
}
if (me.pauseValidate) {
return;
}
// For checkbox and radio
elem = el.name && _checkable(el) ? me.$el.find('input[name="'+ el.name +'"]').get(0) : el;
// Get field
if (!(field = me.getField(elem)) || !field.rule) {
return;
}
// Cache event type
etype0 = field._e;
field._e = etype;
timely = field.timely;
if (!special) {
if (!timely || (_checkable(el) && etype !== 'click')) {
return;
}
value = field.getValue();
// not validate field unless fill a value
if ( field.ignoreBlank && !value && !focusin ) {
me.hideMsg(el);
return;
}
if ( etype === 'focusout' ) {
if (etype0 === 'change') {
return;
}
if ( timely === 2 || timely === 8 ) {
old = field.old;
if (value && old) {
if (field.isValid && !old.showOk) {
me.hideMsg(el);
} else {
me._makeMsg(el, field, old);
}
} else {
return;
}
}
}
else {
if ( timely < 2 && !e.data ) {
return;
}
// mark timestamp to reduce the frequency of the received event
timestamp = +new Date();
if ( timestamp - (el._ts || 0) < 100 ) {
return;
}
el._ts = timestamp;
// handle keyup
if ( etype === 'keyup' ) {
if (etype0 === 'input') {
return;
}
key = e.keyCode;
specialKey = {
8: 1, // Backspace
9: 1, // Tab
16: 1, // Shift
32: 1, // Space
46: 1 // Delete
};
// only gets focus, no validation
if ( key === 9 && !value ) {
return;
}
// do not validate, if triggered by these keys
if ( key < 48 && !specialKey[key] ) {
return;
}
}
if ( !focusin ) {
// keyboard events, reducing the frequency of validation
timer = timely <100 ? (etype === 'click' || el.tagName === 'SELECT') ? 0 : 400 : timely;
}
}
}
// if the current field is ignored
if ( opt.ignore && $(el).is(opt.ignore) ) {
return;
}
clearTimeout(field._t);
if (timer) {
field._t = setTimeout(function() {
me._validate(el, field);
}, timer);
} else {
if (special) field.old = {};
me._validate(el, field);
}
},
_setClass: function(el, isValid) {
var $el = $(el), opt = this.options;
if (opt.bindClassTo) {
$el = $el.closest(opt.bindClassTo);
}
$el.removeClass( opt.invalidClass + ' ' + opt.validClass );
if (isValid !== null) {
$el.addClass( isValid ? opt.validClass : opt.invalidClass );
}
},
_showmsg: function(e, type, msg) {
var me = this,
el = e.target;
if ( me.$el.is(el) ) {
if (isObject(type)) {
me.showMsg(type)
}
else if ( type === 'tip' ) {
me.$el.find(INPUT_SELECTOR +"["+ DATA_TIP +"]", el).each(function(){
me.showMsg(this, {type: type, msg: msg});
});
}
}
else {
me.showMsg(el, {type: type, msg: msg});
}
},
_hidemsg: function(e) {
var $el = $(e.target);
if ( $el.is(INPUT_SELECTOR) ) {
this.hideMsg($el);
}
},
// Validated a field
_validatedField: function(el, field, ret) {
var me = this,
opt = me.options,
isValid = field.isValid = ret.isValid = !!ret.isValid,
callback = isValid ? 'valid' : 'invalid';
ret.key = field.key;
ret.ruleName = field._r;
ret.id = el.id;
ret.value = field.value;
me.elements[field.key] = ret.element = el;
me.isValid = me.$el[0].isValid = isValid ? me.isFormValid() : isValid;
if (isValid) {
ret.type = 'ok';
} else {
if (me.submiting) {
me.errors[field.key] = ret.msg;
}
me.hasError = true;
}
// cache result
field.old = ret;
// trigger callback
isFunction(field[callback]) && field[callback].call(me, el, ret);
isFunction(opt.validation) && opt.validation.call(me, el, ret);
// trigger event
$(el).attr( ARIA_INVALID, isValid ? null : true )
.trigger( callback + CLS_NS_FIELD, [ret, me] );
me.$el.triggerHandler('validation', [ret, me]);
if (me.checkOnly) return;
// set className
me._setClass(el, ret.skip || ret.type === 'tip' ? null : isValid);
me._makeMsg.apply(me, arguments);
},
_makeMsg: function(el, field, ret) {
// show or hide the message
if (field.msgMaker) {
ret = $.extend({}, ret);
if (field._e === 'focusin') {
ret.type = 'tip';
}
this[ ret.showOk || ret.msg || ret.type === 'tip' ? 'showMsg' : 'hideMsg' ](el, ret, field);
}
},
// Validated a rule
_validatedRule: function(el, field, ret, msgOpt) {
field = field || me.getField(el);
msgOpt = msgOpt || {};
var me = this,
msg,
rule,
method = field._r,
timely = field.timely,
special = timely === 9 || timely === 8,
transfer,
temp,
isValid = false;
// use null to break validation from a field
if (ret === null) {
me._validatedField(el, field, {isValid: true, skip: true});
field._i = 0;
return;
}
else if (ret === undefined) {
transfer = true;
}
else if (ret === true || ret === '') {
isValid = true;
}
else if (isString(ret)) {
msg = ret;
}
else if (isObject(ret)) {
if (ret.error) {
msg = ret.error;
} else {
msg = ret.ok;
isValid = true;
}
}
else {
isValid = !!ret
}
rule = field._rules[field._i];
if (rule.not) {
msg = undefined;
isValid = method === "required" || !isValid;
}
if (rule.or) {
if (isValid) {
while ( field._i < field._rules.length && field._rules[field._i].or ) {
field._i++;
}
} else {
transfer = true;
}
}
else if (rule.and) {
if (!field.isValid) transfer = true;
}
if (transfer) {
isValid = true;
}
// message analysis, and throw rule level event
else {
if (isValid) {
if (field.showOk !== false) {
temp = attr(el, DATA_OK);
msg = temp === null ? isString(field.ok) ? field.ok : msg : temp;
if (!isString(msg) && isString(field.showOk)) {
msg = field.showOk;
}
if (isString(msg)) {
msgOpt.showOk = isValid;
}
}
}
if (!isValid || special) {
/* rule message priority:
1. custom DOM message
2. custom field message;
3. global defined message;
4. rule returned message;
5. default message;
*/
msg = (_getDataMsg(el, field, msg || rule.msg || me.messages[method]) || me.messages.fallback).replace(/\{0\|?([^\}]*)\}/, function(m, defaultDisplay){
return me._getDisplay(el, field.display) || defaultDisplay || me.messages[0];
});
}
if (!isValid) field.isValid = isValid;
msgOpt.msg = msg;
$(el).trigger( (isValid ? 'valid' : 'invalid') + CLS_NS_RULE, [method, msg]);
}
if (special && (!transfer || rule.and)) {
if (!isValid && !field._m) field._m = msg;
field._v = field._v || [];
field._v.push({
type: isValid ? !transfer ? 'ok' : 'tip' : 'error',
msg: msg || rule.msg
});
}
me._debug('log', ' ' + field._i + ': ' + method + ' => ' + (isValid || msg));
// the current rule has passed, continue to validate
if ( (isValid || special) && field._i < field._rules.length - 1) {
field._i++;
me._checkRule(el, field);
}
// field was invalid, or all fields was valid
else {
field._i = 0;
if (special) {
msgOpt.isValid = field.isValid;
msgOpt.result = field._v;
msgOpt.msg = field._m || '';
if (!field.value && (field._e === 'focusin')) {
msgOpt.type = 'tip';
}
} else {
msgOpt.isValid = isValid;
}
me._validatedField(el, field, msgOpt);
delete field._m;
delete field._v;
}
},
// Verify a rule form a field
_checkRule: function(el, field) {
var me = this,
ret,
fn,
old,
key = field.key,
rule = field._rules[field._i],
method = rule.method,
params = rule.params;
// request has been sent, wait it
if (me.submiting && me.deferred[key]) {
return;
}
old = field.old;
field._r = method;
if (old && !field.must && !rule.must && rule.result !== undefined &&
old.ruleName === method && old.id === el.id &&
field.value && old.value === field.value )
{
// get result from cache
ret = rule.result;
}
else {
// get result from current rule
fn = _getDataRule(el, method) || me.rules[method] || noop;
ret = fn.call(field, el, params, field);
if (fn.msg) rule.msg = fn.msg;
}
// asynchronous validation
if (isObject(ret) && isFunction(ret.then)) {
me.deferred[key] = ret;
// whether the field valid is unknown
field.isValid = undefined;
// show loading message
!me.checkOnly && me.showMsg(el, {
type: 'loading',
msg: me.messages.loading
}, field);
// waiting to parse the response data
ret.then(
function(d, textStatus, jqXHR) {
var data = trim(jqXHR.responseText),
result,
dataFilter = field.dataFilter;
// detect if data is json or jsonp format
if (/jsonp?/.test(this.dataType)) {
data = d;
} else if (data.charAt(0) === '{') {
data = $.parseJSON(data);
}
// filter data
result = dataFilter.call(this, data, field);
if (result === undefined) result = dataFilter.call(this, data.data, field);
rule.data = this.data;
rule.result = field.old ? result : undefined;
me._validatedRule(el, field, result);
},
function(jqXHR, textStatus){
me._validatedRule(el, field, me.messages[textStatus] || textStatus);
}
).always(function(){
delete me.deferred[key];
});
}
// other result
else {
me._validatedRule(el, field, ret);
}
},
// Processing the validation
_validate: function(el, field) {
var me = this;
// doesn't validate the element that has "disabled" or "novalidate" attribute
if ( el.disabled || attr(el, NOVALIDATE) !== null ) {
return;
}
field = field || me.getField(el);
if (!field) return;
if (!field._rules) me._parse(el);
if (!field._rules) return;
me._debug('info', field.key);
field.isValid = true;
field.element = el;
// Cache the value
field.value = field.getValue();
// if the field is not required, and that has a blank value
if (!field.required && !field.must && !field.value) {
if (!_checkable(el)) {
me._validatedField(el, field, {isValid: true});
return true;
}
}
me._checkRule(el, field);
return field.isValid;
},
_debug: function(type, messages) {
if (window.console && this.options.debug) {
console[type](messages);
}
},
/**
* Detecting whether the value of an element that matches a rule
*
* @method test
* @param {Element} el - input element
* @param {String} rule - rule name
*/
test: function(el, rule) {
var me = this,
ret,
parts = rRule.exec(rule),
field,
method,
params;
if (parts) {
method = parts[1];
if (method in me.rules) {
params = parts[2] || parts[3];
params = params ? params.split(', ') : undefined;
field = me.getField(el, true);
field._r = method;
field.value = field.getValue();
ret = me.rules[method].call(field, el, params);
}
}
return ret === true || ret === undefined || ret === null;
},
_getDisplay: function(el, str) {
return !isString(str) ? isFunction(str) ? str.call(this, el) : '' : str;
},
_getMsgOpt: function(obj, field) {
var opt = field ? field : this.options;
return $.extend({
type: 'error',
pos: _getPos(opt.msgClass),
target: opt.target,
wrapper: opt.msgWrapper,
style: opt.msgStyle,
cls: opt.msgClass,
arrow: opt.msgArrow,
icon: opt.msgIcon
}, isString(obj) ? {msg: obj} : obj);
},
_getMsgDOM: function(el, msgOpt) {
var $el = $(el), $msgbox, datafor, tgt, container;
if ( $el.is(INPUT_SELECTOR) ) {
tgt = msgOpt.target || attr(el, DATA_TARGET);
if (tgt) {
tgt = !isFunction(tgt) ? tgt.charAt(0) === '#' ? $(tgt) : this.$el.find(tgt) : tgt.call(this, el);
if (tgt.length) {
if ( tgt.is(INPUT_SELECTOR) ) {
$el = tgt
el = tgt.get(0);
} else if ( tgt.hasClass(CLS_MSG_BOX) ) {
$msgbox = tgt;
} else {
container = tgt;
}
}
}
if (!$msgbox) {
datafor = (!_checkable(el) || !el.name) && el.id ? el.id : el.name;
$msgbox = (container || this.$el).find(msgOpt.wrapper + '.' + CLS_MSG_BOX + '[for="' + datafor + '"]');
}
} else {
$msgbox = $el;
}
// Create new message box
if (!msgOpt.hide && !$msgbox.length) {
$msgbox = $('<'+ msgOpt.wrapper + '>').attr({
'class': CLS_MSG_BOX + (msgOpt.cls ? ' ' + msgOpt.cls : ''),
'style': msgOpt.style || undefined,
'for': datafor
});
if (container) {
$msgbox.appendTo(container);
} else {
if ( _checkable(el) ) {
var $parent = $el.parent();
$msgbox.appendTo( $parent.is('label') ? $parent.parent() : $parent );
} else {
$msgbox[!msgOpt.pos || msgOpt.pos === 'right' ? 'insertAfter' : 'insertBefore']($el);
}
}
}
return $msgbox;
},
/**
* Show validation message
*
* @method showMsg
* @param {Element} el - input element
* @param {Object} msgOpt
*/
showMsg: function(el, msgOpt, /*INTERNAL*/ field) {
if (!el) return;
var me = this,
opt = me.options,
msgShow,
msgMaker,
temp,
$msgbox;
if (isObject(el) && !el.jquery && !msgOpt) {
$.each(el, function(key, msg) {
var el = me.elements[key] || me.$el.find(_key2selector(key))[0];
me.showMsg(el, msg);
});
return;
}
if ($(el).is(INPUT_SELECTOR)) {
field = field || me.getField(el);
}
if (!(msgMaker = (field || opt).msgMaker)) {
return;
}
msgOpt = me._getMsgOpt(msgOpt, field);
el = (el.name && _checkable(el) ? me.$el.find('input[name="'+ el.name +'"]') : $(el)).get(0);
// ok or tip
if (!msgOpt.msg && msgOpt.type !== 'error') {
temp = attr(el, 'data-' + msgOpt.type);
if (temp !== null) msgOpt.msg = temp;
}
if ( !isString(msgOpt.msg) ) {
return;
}
$msgbox = me._getMsgDOM(el, msgOpt);
!rPos.test($msgbox[0].className) && $msgbox.addClass(msgOpt.cls);
if ( isIE === 6 && msgOpt.pos === 'bottom' ) {
$msgbox[0].style.marginTop = $(el).outerHeight() + 'px';
}
$msgbox.html( msgMaker.call(me, msgOpt) )[0].style.display = '';
if (isFunction(msgShow = field && field.msgShow || opt.msgShow)) {
msgShow.call(me, $msgbox, msgOpt.type);
}
},
/**
* Hide validation message
*
* @method hideMsg
* @param {Element} el - input element
* @param {Object} msgOpt optional
*/
hideMsg: function(el, msgOpt, /*INTERNAL*/ field) {
var me = this,
opt = me.options,
msgHide,
$msgbox;
el = $(el).get(0);
if ($(el).is(INPUT_SELECTOR)) {
field = field || me.getField(el);
if (field) {
if (field.isValid || me.reseting) attr(el, ARIA_INVALID, null);
}
}
msgOpt = me._getMsgOpt(msgOpt, field);
msgOpt.hide = true;
$msgbox = me._getMsgDOM(el, msgOpt);
if (!$msgbox.length) return;
if ( isFunction(msgHide = field && field.msgHide || opt.msgHide) ) {
msgHide.call(me, $msgbox, msgOpt.type);
} else {
$msgbox[0].style.display = 'none';
$msgbox[0].innerHTML = '';
}
},
/**
* Get field information
*
* @method getField
* @param {Element} - input element
* @return {Object} field
*/
getField: function(el, must) {
var me = this,
key,
field;
if (isString(el)) {
key = el;
el = undefined;
} else {
if (attr(el, DATA_RULE)) {
return me._parse(el);
}
if (el.id && '#' + el.id in me.fields || !el.name) {
key = '#' + el.id;
} else {
key = el.name;
}
}
if ( (field = me.fields[key]) || must && (field = new me.Field(key)) ) {
field.element = el;
}
return field;
},
/**
* Config a field
*
* @method: setField
* @param {String} key
* @param {Object} obj
*/
setField: function(key, obj) {
var fields = {};
if (!key) return;
// update this field
if (isString(key)) {
fields[key] = obj;
}
// update fields
else {
fields = key;
}
this._initFields(fields);
},
/**
* Detecting whether the form is valid
*
* @method isFormValid
* @return {Boolean}
*/
isFormValid: function() {
var fields = this.fields, k, field;
for (k in fields) {
field = fields[k];
if (!field._rules || !field.required && !field.must && !field.value) continue;
if (!field.isValid) return false;
}
return true;
},
/**
* Prevent submission form
*
* @method holdSubmit
* @param {Boolean} hold - If set to false, will release the hold
*/
holdSubmit: function(hold) {
this.submiting = hold === undefined || hold;
},
/**
* Clean validation messages
*
* @method cleanUp
*/
cleanUp: function() {
this._reset(1);
},
/**
* Destroy the validation
*
* @method destroy
*/
destroy: function() {
this._reset(1);
this.$el.off(CLS_NS).removeData(NS);
attr(this.$el[0], NOVALIDATE, this._NOVALIDATE);
}
};
/**
* Create Field Factory
*
* @class
* @param {Object} context
* @return {Function} Factory
*/
function _createFieldFactory(context) {
function FieldFactory() {
var options = this.options;
for (var i in options) {
if (i in fieldDefaults) this[i] = options[i];
}
$.extend(this, {
_valHook: function() {
return this.element.contentEditable === 'true' ? 'text' : 'val';
},
getValue: function() {
var elem = this.element;
if (elem.type === "number" && elem.validity && elem.validity.badInput) {
return 'NaN';
}
return $(elem)[this._valHook()]();
},
setValue: function(value) {
$(this.element)[this._valHook()](this.value = value);
},
// Get a range of validation messages
getRangeMsg: function(value, params, suffix) {
if (!params) return;
var me = this,
msg = me.messages[me._r] || '',
result,
p = params[0].split('~'),
e = params[1] === 'false',
a = p[0],
b = p[1],
c = 'rg',
args = [''],
isNumber = trim(value) && +value === +value;
function compare(large, small) {
return !e ? large >= small : large > small;
}
if (p.length === 2) {
if (a && b) {
if (isNumber && compare(value, +a) && compare(+b, value)) {
result = true;
}
args = args.concat(p);
c = e ? 'gtlt' : 'rg';
}
else if (a && !b) {
if (isNumber && compare(value, +a)) {
result = true;
}
args.push(a);
c = e ? 'gt' : 'gte';
}
else if (!a && b) {
if (isNumber && compare(+b, value)) {
result = true;
}
args.push(b);
c = e ? 'lt' : 'lte';
}
}
else {
if (value === +a) {
result = true;
}
args.push(a);
c = 'eq';
}
if (msg) {
if (suffix && msg[c + suffix]) {
c += suffix;
}
args[0] = msg[c];
}
return result || me._rules && ( me._rules[me._i].msg = me.renderMsg.apply(null, args) );
},
// Render message template
renderMsg: function() {
var args = arguments,
tpl = args[0],
i = args.length;
if (!tpl) return;
while (--i) {
tpl = tpl.replace('{' + i + '}', args[i]);
}
return tpl;
}
});
}
function Field(key, obj, oldField) {
this.key = key;
this.validator = context;
$.extend(this, oldField, obj);
}
FieldFactory.prototype = context;
Field.prototype = new FieldFactory();
return Field;
}
/**
* Create Rules
*
* @class
* @param {Object} obj rules
* @param {Object} context context
*/
function Rules(obj, context) {
if (!isObject(obj)) return;
var k, that = context ? context === true ? this : context : Rules.prototype;
for (k in obj) {
if (_checkRuleName(k))
that[k] = _getRule(obj[k]);
}
}
/**
* Create Messages
*
* @class
* @param {Object} obj rules
* @param {Object} context context
*/
function Messages(obj, context) {
if (!isObject(obj)) return;
var k, that = context ? context === true ? this : context : Messages.prototype;
for (k in obj) {
that[k] = obj[k];
}
}
// Rule converted factory
function _getRule(fn) {
switch ($.type(fn)) {
case 'function':
return fn;
case 'array':
var f = function() {
return fn[0].test(this.value) || fn[1] || false;
};
f.msg = fn[1];
return f;
case 'regexp':
return function() {
return fn.test(this.value);
};
}
}
// Get instance by an element
function _getInstance(el) {
var wrap, k, options;
if (!el || !el.tagName) return;
switch (el.tagName) {
case 'INPUT':
case 'SELECT':
case 'TEXTAREA':
case 'BUTTON':
case 'FIELDSET':
wrap = el.form || $(el).closest('.' + CLS_WRAPPER);
break;
case 'FORM':
wrap = el;
break;
default:
wrap = $(el).closest('.' + CLS_WRAPPER);
}
for (k in preinitialized) {
if ($(wrap).is(k)) {
options = preinitialized[k];
break;
}
}
return $(wrap).data(NS) || $(wrap)[NS](options).data(NS);
}
// Get custom rules on the node
function _getDataRule(el, method) {
var fn = trim(attr(el, DATA_RULE + '-' + method));
if ( fn && (fn = new Function("return " + fn)()) ) {
return _getRule(fn);
}
}
// Get custom messages on the node
function _getDataMsg(el, field, m) {
var msg = field.msg,
item = field._r;
if ( isObject(msg) ) msg = msg[item];
if ( !isString(msg) ) {
msg = attr(el, DATA_MSG + '-' + item) || attr(el, DATA_MSG) || ( m ? isString(m) ? m : m[item] : '');
}
return msg;
}
// Get message position
function _getPos(str) {
var pos;
if (str) pos = rPos.exec(str);
return pos && pos[0];
}
// Check whether the element is checkbox or radio
function _checkable(el) {
return el.tagName === 'INPUT' && el.type === 'checkbox' || el.type === 'radio';
}
// Parse date string to timestamp
function _parseDate(str) {
return Date.parse(str.replace(/\.|\-/g, '/'));
}
// Rule name only allows alphanumeric characters and underscores
function _checkRuleName(name) {
return /^\w+$/.test(name);
}
// Translate field key to jQuery selector.
function _key2selector(key) {
var isID = key.charAt(0) === "#";
key = key.replace(/([:.{(|)}/\[\]])/g, "\\$1");
return isID ? key : '[name="'+ key +'"]:first';
}
// Fixed a issue cause by refresh page in IE.
$(window).on('beforeunload', function(){
this.focus();
});
$(document)
.on('click', ':submit', function(){
var input = this, attrNode;
if (!input.form) return;
// Shim for "formnovalidate"
attrNode = input.getAttributeNode('formnovalidate');
if (attrNode && attrNode.nodeValue !== null || attr(input, NOVALIDATE)!== null) {
novalidateonce = true;
}
})
// Automatic initializing form validation
.on('focusin submit validate', 'form,.'+CLS_WRAPPER, function(e) {
if ( attr(this, NOVALIDATE) !== null ) return;
var $form = $(this), me;
if ( !$form.data(NS) && (me = _getInstance(this)) ) {
if ( !$.isEmptyObject(me.fields) ) {
// Execute event handler
if (e.type === 'focusin') {
me._focusin(e);
} else {
me._submit(e);
}
} else {
attr(this, NOVALIDATE, NOVALIDATE);
$form.off(CLS_NS).removeData(NS);
}
}
});
new Messages({
fallback: "This field is not valid.",
loading: 'Validating...'
});
// Built-in rules (global)
new Rules({
/**
* required
*
* @example:
required
required(anotherRule)
required(not, -1)
required(from, .contact)
*/
required: function(element, params) {
var me = this,
val = trim(me.value),
isValid = true;
if (params) {
if ( params.length === 1 ) {
if ( !_checkRuleName(params[0]) ) {
if (!val && !$(params[0], me.$el).length ) {
return null;
}
}
else if ( me.rules[params[0]] ) {
if ( !val && !me.test(element, params[0]) ) {
return null;
}
}
}
else if ( params[0] === 'not' ) {
$.each(params.slice(1), function() {
return (isValid = val !== trim(this));
});
}
else if ( params[0] === 'from' ) {
var $elements = me.$el.find(params[1]),
VALIDATED = '_validated_',
ret;
isValid = $elements.filter(function(){
var field = me.getField(this);
return field && !!trim(field.getValue());
}).length >= (params[2] || 1);
if (isValid) {
if (!val) ret = null;
} else {
ret = _getDataMsg($elements[0], me) || false;
}
if ( !$(element).data(VALIDATED) ) {
$elements.data(VALIDATED, 1).each(function(){
if (element !== this) {
me._validate(this);
}
}).removeData(VALIDATED);
}
return ret;
}
}
return isValid && !!val;
},
/**
* integer
*
* @example:
integer
integer[+]
integer[+0]
integer[-]
integer[-0]
*/
integer: function(element, params) {
var re, z = '0|',
p = '[1-9]\\d*',
key = params ? params[0] : '*';
switch (key) {
case '+':
re = p;
break;
case '-':
re = '-' + p;
break;
case '+0':
re = z + p;
break;
case '-0':
re = z + '-' + p;
break;
default:
re = z + '-?' + p;
}
re = '^(?:' + re + ')$';
return new RegExp(re).test(this.value) || (this.messages.integer && this.messages.integer[key]);
},
/**
* match another field
*
* @example:
match[password] Match the password field (two values ​​must be the same)
match[eq, password] Ditto
match[neq, count] The value must be not equal to the value of the count field
match[lt, count] The value must be less than the value of the count field
match[lte, count] The value must be less than or equal to the value of the count field
match[gt, count] The value must be greater than the value of the count field
match[gte, count] The value must be greater than or equal to the value of the count field
match[gte, startDate, date]
match[gte, startTime, time]
**/
match: function(element, params) {
if (!params) return;
var me = this,
isValid = true,
a, b,
key, msg, type = 'eq', parser,
selector2, elem2, field2;
if (params.length === 1) {
key = params[0];
} else {
type = params[0];
key = params[1];
}
selector2 = _key2selector(key);
elem2 = me.$el.find(selector2)[0];
// If the compared field is not exist
if (!elem2) return;
field2 = me.getField(elem2);
a = me.value;
b = field2.getValue();
if (!me._match) {
me.$el.on('valid'+CLS_NS_FIELD+CLS_NS, selector2, function(){
$(element).trigger('validate');
});
me._match = field2._match = 1;
}
// If both fields are blank
if (!me.required && a === "" && b === "") {
return null;
}
parser = params[2];
if (parser) {
if (/^date(time)?$/i.test(parser)) {
a = _parseDate(a);
b = _parseDate(b);
} else if (parser === 'time') {
a = +a.replace(/:/g, '');
b = +b.replace(/:/g, '');
}
}
// If the compared field is incorrect, we only ensure that this field is correct.
if (type !== "eq" && !isNaN(+a) && isNaN(+b)) {
return true;
}
switch (type) {
case 'lt':
isValid = +a < +b; break;
case 'lte':
isValid = +a <= +b; break;
case 'gte':
isValid = +a >= +b; break;
case 'gt':
isValid = +a > +b; break;
case 'neq':
isValid = a !== b; break;
default:
isValid = a === b;
}
return isValid || (
isObject(me.messages.match)
&& me.messages.match[type].replace( '{1}', me._getDisplay( element, field2.display || key ) )
);
},
/**
* range numbers
*
* @example:
range[0~99] Number 0-99
range[0~] Number greater than or equal to 0
range[~100] Number less than or equal to 100
**/
range: function(element, params) {
return this.getRangeMsg(this.value, params);
},
/**
* how many checkbox or radio inputs that checked
*
* @example:
checked; no empty, same to required
checked[1~3] 1-3 items
checked[1~] greater than 1 item
checked[~3] less than 3 items
checked[3] 3 items
**/
checked: function(element, params) {
if ( !_checkable(element) ) return;
var me = this,
elem, count;
if (element.name) {
count = me.$el.find('input[name="' + element.name + '"]').filter(function() {
var el = this;
if (!elem && _checkable(el)) elem = el;
return !el.disabled && el.checked;
}).length;
} else {
elem = element;
count = elem.checked;
}
if (params) {
return me.getRangeMsg(count, params);
} else {
return !!count || _getDataMsg(elem, me, '') || me.messages.required || false;
}
},
/**
* length of a characters (You can pass the second parameter "true", will calculate the length in bytes)
*
* @example:
length[6~16] 6-16 characters
length[6~] Greater than 6 characters
length[~16] Less than 16 characters
length[~16, true] Less than 16 characters, non-ASCII characters calculating two-character
**/
length: function(element, params) {
var value = this.value,
len = (params[1] === 'true' ? value.replace(rDoubleBytes, 'xx') : value).length;
return this.getRangeMsg(len, params, (params[1] ? '_2' : ''));
},
/**
* remote validation
*
* @description
* remote([get:]url [, name1, [name2 ...]]);
* Adaptation three kinds of results (Front for the successful, followed by a failure):
1. text:
'' 'Error Message'
2. json:
{"ok": ""} {"error": "Error Message"}
3. json wrapper:
{"status": 1, "data": {"ok": ""}} {"status": 1, "data": {"error": "Error Message"}}
* @example
The simplest: remote(path/to/server);
With parameters: remote(path/to/server, name1, name2, ...);
By GET: remote(get:path/to/server, name1, name2, ...);
Name proxy: remote(path/to/server, name1, proxyname2:name2, proxyname3:#id3, ...)
Query String remote(path/to/server, foo=1&bar=2, name1, name2, ...)
*/
remote: function(element, params) {
if (!params) return;
var me = this,
arr = rAjaxType.exec(params[0]),
rule = me._rules[me._i],
data = {},
queryString = '',
url = arr[3],
type = arr[2] || 'POST', // GET / POST
rType = (arr[1]||'').toLowerCase(), // CORS / JSONP
dataType;
rule.must = true;
data[element.name] = me.value;
// There are extra fields
if (params[1]) {
$.map(params.slice(1), function(name) {
var arr, key;
if (~name.indexOf('=')) {
queryString += '&' + name;
} else {
arr = name.split(':');
name = trim(arr[0]);
key = trim(arr[1]) || name;
data[ name ] = me.$el.find( _key2selector(key) ).val();
}
});
}
data = $.param(data) + queryString;
if (!me.must && rule.data && rule.data === data) {
return rule.result;
}
// Cross-domain request, force jsonp dataType
if (rType !== 'cors' && /^https?:/.test(url) && !~url.indexOf(location.host)) {
dataType = 'jsonp';
}
// Asynchronous validation need return jqXHR objects
return $.ajax({
url: url,
type: type,
data: data,
dataType: dataType
});
},
/**
* filter characters, direct filtration without prompting error (support custom regular expressions)
*
* @example
* filter filtering unsafe characters
* filter(regexp) filtering the "regexp" matched characters
*/
filter: function(element, params) {
var value = this.value,
temp = value.replace( params ? (new RegExp("[" + params[0] + "]", "gm")) : rUnsafe, '' );
if (temp !== value) this.setValue(temp);
}
});
/**
* Config global options
*
* @static config
* @param {Object} options
*/
Validator.config = function(key, value) {
if (isObject(key)) {
$.each(key, _config);
}
else if (isString(key)) {
_config(key, value);
}
function _config(k, o) {
if (k === 'rules') {
new Rules(o);
}
else if (k === 'messages') {
new Messages(o);
}
else if (k in fieldDefaults) {
fieldDefaults[k] = o;
}
else {
defaults[k] = o;
}
}
};
/**
* Config themes
*
* @static setTheme
* @param {String|Object} name
* @param {Object} obj
* @example
.setTheme( themeName, themeOptions )
.setTheme( multiThemes )
*/
Validator.setTheme = function(name, obj) {
if ( isObject(name) ) {
$.extend(true, themes, name);
}
else if ( isString(name) && isObject(obj) ) {
themes[name] = $.extend(themes[name], obj);
}
};
/**
* Resource loader
*
* @static load
* @param {String} str
* @example
.load('local=zh-CN') // load: local/zh-CN.js and jquery.validator.css
.load('local=zh-CN&css=') // load: local/zh-CN.js
.load('local&css') // load: local/en.js (set <html lang="en">) and jquery.validator.css
.load('local') // dito
*/
Validator.load = function(str) {
if (!str) return;
var doc = document,
params = {},
node = doc.scripts[0],
dir, el, ONLOAD;
str.replace(/([^?=&]+)=([^&#]*)/g, function(m, key, value){
params[key] = value;
});
dir = params.dir || Validator.dir;
if (!Validator.css && params.css !== '') {
el = doc.createElement('link');
el.rel = 'stylesheet';
el.href = Validator.css = dir + 'jquery.validator.css';
node.parentNode.insertBefore(el, node);
}
if (!Validator.local && ~str.indexOf('local') && params.local !== '') {
Validator.local = (params.local || doc.documentElement.lang || 'en').replace('_','-');
Validator.pending = 1;
el = doc.createElement('script');
el.src = dir + 'local/' + Validator.local + '.js';
ONLOAD = 'onload' in el ? 'onload' : 'onreadystatechange';
el[ONLOAD] = function() {
if (!el.readyState || /loaded|complete/.test(el.readyState)) {
el = el[ONLOAD] = null;
delete Validator.pending;
$(window).triggerHandler('validatorready');
}
};
node.parentNode.insertBefore(el, node);
}
};
// Auto loading resources
(function(){
var scripts = document.scripts,
i = scripts.length, node, arr,
re = /(.*validator(?:\.min)?.js)(\?.*(?:local|css|dir)(?:=[\w\-]*)?)?/;
while (i-- && !arr) {
node = scripts[i];
arr = (node.hasAttribute ? node.src : node.getAttribute('src',4)||'').match(re);
}
if (!arr) return;
Validator.dir = arr[1].split('/').slice(0, -1).join('/')+'/';
Validator.load(arr[2]);
})();
return $[NS] = Validator;
}));
/*! nice-validator 1.1.3
* (c) 2012-2017 Jony Zhang <niceue@live.com>, MIT Licensed
* https://github.com/niceue/nice-validator
*/
!function(e){"object"==typeof module&&module.exports?module.exports=e(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)}(function(e,t){"use strict";function i(t,n){function s(){a.$el=e(t),a.$el.length?a._init(a.$el[0],n):W(t)&&(z[t]=n)}var a=this;return a instanceof i?void(i.pending?e(window).on("validatorready",s):s()):new i(t,n)}function n(t){function i(){var t=this.options;for(var i in t)i in K&&(this[i]=t[i]);e.extend(this,{_valHook:function(){return"true"===this.element.contentEditable?"text":"val"},getValue:function(){var t=this.element;return"number"===t.type&&t.validity&&t.validity.badInput?"NaN":e(t)[this._valHook()]()},setValue:function(t){e(this.element)[this._valHook()](this.value=t)},getRangeMsg:function(e,t,i){function n(e,t){return o?e>t:e>=t}if(t){var s,a=this,r=a.messages[a._r]||"",l=t[0].split("~"),o="false"===t[1],u=l[0],d=l[1],c="rg",f=[""],g=P(e)&&+e===+e;return 2===l.length?u&&d?(g&&n(e,+u)&&n(+d,e)&&(s=!0),f=f.concat(l),c=o?"gtlt":"rg"):u&&!d?(g&&n(e,+u)&&(s=!0),f.push(u),c=o?"gt":"gte"):!u&&d&&(g&&n(+d,e)&&(s=!0),f.push(d),c=o?"lt":"lte"):(e===+u&&(s=!0),f.push(u),c="eq"),r&&(i&&r[c+i]&&(c+=i),f[0]=r[c]),s||a._rules&&(a._rules[a._i].msg=a.renderMsg.apply(null,f))}},renderMsg:function(){var e=arguments,t=e[0],i=e.length;if(t){for(;--i;)t=t.replace("{"+i+"}",e[i]);return t}}})}function n(i,n,s){this.key=i,this.validator=t,e.extend(this,s,n)}return i.prototype=t,n.prototype=new i,n}function s(e,t){if(J(e)){var i,n=t?t===!0?this:t:s.prototype;for(i in e)g(i)&&(n[i]=r(e[i]))}}function a(e,t){if(J(e)){var i,n=t?t===!0?this:t:a.prototype;for(i in e)n[i]=e[i]}}function r(t){switch(e.type(t)){case"function":return t;case"array":var i=function(){return t[0].test(this.value)||t[1]||!1};return i.msg=t[1],i;case"regexp":return function(){return t.test(this.value)}}}function l(t){var i,n,s;if(t&&t.tagName){switch(t.tagName){case"INPUT":case"SELECT":case"TEXTAREA":case"BUTTON":case"FIELDSET":i=t.form||e(t).closest("."+k);break;case"FORM":i=t;break;default:i=e(t).closest("."+k)}for(n in z)if(e(i).is(n)){s=z[n];break}return e(i).data(p)||e(i)[p](s).data(p)}}function o(e,t){var i=P(X(e,M+"-"+t));if(i&&(i=new Function("return "+i)()))return r(i)}function u(e,t,i){var n=t.msg,s=t._r;return J(n)&&(n=n[s]),W(n)||(n=X(e,V+"-"+s)||X(e,V)||(i?W(i)?i:i[s]:"")),n}function d(e){var t;return e&&(t=D.exec(e)),t&&t[0]}function c(e){return"INPUT"===e.tagName&&"checkbox"===e.type||"radio"===e.type}function f(e){return Date.parse(e.replace(/\.|\-/g,"/"))}function g(e){return/^\w+$/.test(e)}function m(e){var t="#"===e.charAt(0);return e=e.replace(/([:.{(|)}\/\[\]])/g,"\\$1"),t?e:'[name="'+e+'"]:first'}var h,p="validator",v="."+p,_=".rule",y=".field",b=".form",k="nice-"+p,w="msg-box",x="aria-invalid",M="data-rule",V="data-msg",O="data-tip",F="data-ok",$="data-timely",E="data-target",C="data-display",A="data-must",j="novalidate",N=":verifiable",T=/(&)?(!)?\b(\w+)(?:\[\s*(.*?\]?)\s*\]|\(\s*(.*?\)?)\s*\))?\s*(;|\|)?/g,S=/(\w+)(?:\[\s*(.*?\]?)\s*\]|\(\s*(.*?\)?)\s*\))?/,R=/(?:([^:;\(\[]*):)?(.*)/,q=/[^\x00-\xff]/g,D=/top|right|bottom|left/,I=/(?:(cors|jsonp):)?(?:(post|get):)?(.+)/i,H=/[<>'"`\\]|&#x?\d+[A-F]?;?|%3[A-F]/gim,L=e.noop,B=e.proxy,P=e.trim,U=e.isFunction,W=function(e){return"string"==typeof e},J=function(e){return e&&"[object Object]"===Object.prototype.toString.call(e)},Q=document.documentMode||+(navigator.userAgent.match(/MSIE (\d+)/)&&RegExp.$1),X=function(e,i,n){return e&&e.tagName?n===t?e.getAttribute(i):void(null===n?e.removeAttribute(i):e.setAttribute(i,""+n)):null},z={},G={debug:0,theme:"default",ignore:"",focusInvalid:!0,focusCleanup:!1,stopOnError:!1,beforeSubmit:null,valid:null,invalid:null,validation:null,formClass:"n-default",validClass:"n-valid",invalidClass:"n-invalid",bindClassTo:null},K={timely:1,display:null,target:null,ignoreBlank:!1,showOk:!0,dataFilter:function(e){if(W(e)||J(e)&&("error"in e||"ok"in e))return e},msgMaker:function(t){var i;return i='<span role="alert" class="msg-wrap n-'+t.type+'">'+t.arrow,t.result?e.each(t.result,function(e,n){i+='<span class="n-'+n.type+'">'+t.icon+'<span class="n-msg">'+n.msg+"</span></span>"}):i+=t.icon+'<span class="n-msg">'+t.msg+"</span>",i+="</span>"},msgWrapper:"span",msgArrow:"",msgIcon:'<span class="n-icon"></span>',msgClass:"n-right",msgStyle:"",msgShow:null,msgHide:null},Y={};return e.fn.validator=function(t){var n=this,s=arguments;return n.is(N)?n:(n.is("form")||(n=this.find("form")),n.length||(n=this),n.each(function(){var n=e(this).data(p);if(n)if(W(t)){if("_"===t.charAt(0))return;n[t].apply(n,[].slice.call(s,1))}else t&&(n._reset(!0),n._init(this,t));else new i(this,t)}),this)},e.fn.isValid=function(e,i){var n,s,a=l(this[0]),r=U(e);return!a||(r||i!==t||(i=e),a.checkOnly=!!i,s=a.options,n=a._multiValidate(this.is(N)?this:this.find(N),function(t){t||!s.focusInvalid||a.checkOnly||a.$el.find("["+x+"]:first").focus(),r&&(e.length?e(t):t&&e()),a.checkOnly=!1}),r?this:n)},e.extend(e.expr.pseudos||e.expr[":"],{verifiable:function(e){var t=e.nodeName.toLowerCase();return("input"===t&&!{submit:1,button:1,reset:1,image:1}[e.type]||"select"===t||"textarea"===t||"true"===e.contentEditable)&&!e.disabled},filled:function(t){return!!P(e(t).val())}}),i.prototype={_init:function(t,i){var r,l,o,u=this;U(i)&&(i={valid:i}),i=u._opt=i||{},o=X(t,"data-"+p+"-option"),o=u._dataOpt=o&&"{"===o.charAt(0)?new Function("return "+o)():{},l=u._themeOpt=Y[i.theme||o.theme||G.theme],r=u.options=e.extend({},G,K,l,u.options,i,o),u.rules=new s(r.rules,(!0)),u.messages=new a(r.messages,(!0)),u.Field=n(u),u.elements=u.elements||{},u.deferred={},u.errors={},u.fields={},u._initFields(r.fields),u.$el.data(p)||(u.$el.data(p,u).addClass(k+" "+r.formClass).on("form-submit-validate",function(e,t,i,n,s){u.vetoed=s.veto=!u.isValid,u.ajaxFormOptions=n}).on("submit"+v+" validate"+v,B(u,"_submit")).on("reset"+v,B(u,"_reset")).on("showmsg"+v,B(u,"_showmsg")).on("hidemsg"+v,B(u,"_hidemsg")).on("focusin"+v+" click"+v,N,B(u,"_focusin")).on("focusout"+v+" validate"+v,N,B(u,"_focusout")).on("keyup"+v+" input"+v+" compositionstart compositionend",N,B(u,"_focusout")).on("click"+v,":radio,:checkbox","click",B(u,"_focusout")).on("change"+v,'select,input[type="file"]',"change",B(u,"_focusout")),u._NOVALIDATE=X(t,j),X(t,j,j)),W(r.target)&&u.$el.find(r.target).addClass("msg-container")},_guessAjax:function(t){function i(t,i,n){return!!(t&&t[i]&&e.map(t[i],function(e){return~e.namespace.indexOf(n)?1:null}).length)}var n=this;if(!(n.isAjaxSubmit=!!n.options.valid)){var s=(e._data||e.data)(t,"events");n.isAjaxSubmit=i(s,"valid","form")||i(s,"submit","form-plugin")}},_initFields:function(e){function t(e,t){if(null===t||r){var i=a.elements[e];i&&a._resetElement(i,!0),delete a.fields[e]}else a.fields[e]=new a.Field(e,W(t)?{rule:t}:t,a.fields[e])}var i,n,s,a=this,r=null===e;if(r&&(e=a.fields),J(e))for(i in e)if(~i.indexOf(","))for(n=i.split(","),s=n.length;s--;)t(P(n[s]),e[i]);else t(i,e[i]);a.$el.find(N).each(function(){a._parse(this)})},_parse:function(e){var t,i,n,s=this,a=e.name,r=X(e,M);return r&&X(e,M,null),e.id&&("#"+e.id in s.fields||!a||null!==r&&(t=s.fields[a])&&r!==t.rule&&e.id!==t.key)&&(a="#"+e.id),a||(a="#"+(e.id="N"+String(Math.random()).slice(-12))),t=s.getField(a,!0),t.rule=r||t.rule,(i=X(e,C))&&(t.display=i),t.rule&&((null!==X(e,A)||/\b(?:match|checked)\b/.test(t.rule))&&(t.must=!0),/\brequired\b/.test(t.rule)&&(t.required=!0),(n=X(e,$))?t.timely=+n:t.timely>3&&X(e,$,t.timely),s._parseRule(t),t.old={}),W(t.target)&&X(e,E,t.target),W(t.tip)&&X(e,O,t.tip),s.fields[a]=t},_parseRule:function(i){var n=R.exec(i.rule);n&&(i._i=0,n[1]&&(i.display=n[1]),n[2]&&(i._rules=[],n[2].replace(T,function(){var n=arguments;n[4]=n[4]||n[5],i._rules.push({and:"&"===n[1],not:"!"===n[2],or:"|"===n[6],method:n[3],params:n[4]?e.map(n[4].split(", "),P):t})})))},_multiValidate:function(i,n){var s=this,a=s.options;return s.hasError=!1,a.ignore&&(i=i.not(a.ignore)),i.each(function(){if(s._validate(this),s.hasError&&a.stopOnError)return!1}),n&&(s.validating=!0,e.when.apply(null,e.map(s.deferred,function(e){return e})).done(function(){n.call(s,!s.hasError),s.validating=!1})),e.isEmptyObject(s.deferred)?!s.hasError:t},_submit:function(i){var n=this,s=n.options,a=i.target,r="submit"===i.type&&"FORM"===a.tagName&&!i.isDefaultPrevented();i.preventDefault(),h&&~(h=!1)||n.submiting||"validate"===i.type&&n.$el[0]!==a||U(s.beforeSubmit)&&s.beforeSubmit.call(n,a)===!1||(n.isAjaxSubmit===t&&n._guessAjax(a),n._debug("log","\n<<< event: "+i.type),n._reset(),n.submiting=!0,n._multiValidate(n.$el.find(N),function(t){var i,l=t||2===s.debug?"valid":"invalid";t||(s.focusInvalid&&n.$el.find("["+x+"]:first").focus(),i=e.map(n.errors,function(e){return e})),n.submiting=!1,n.isValid=t,U(s[l])&&s[l].call(n,a,i),n.$el.trigger(l+b,[a,i]),n._debug("log",">>> "+l),t&&(n.vetoed?e(a).ajaxSubmit(n.ajaxFormOptions):r&&!n.isAjaxSubmit&&document.createElement("form").submit.call(a))}))},_reset:function(e){var t=this;t.errors={},e&&(t.reseting=!0,t.$el.find(N).each(function(){t._resetElement(this)}),delete t.reseting)},_resetElement:function(e,t){this._setClass(e,null),this.hideMsg(e)},_focusin:function(e){var t,i,n=this,s=n.options,a=e.target;n.validating||"click"===e.type&&document.activeElement===a||(s.focusCleanup&&"true"===X(a,x)&&(n._setClass(a,null),n.hideMsg(a)),i=X(a,O),i?n.showMsg(a,{type:"tip",msg:i}):(X(a,M)&&n._parse(a),(t=X(a,$))&&(8!==t&&9!==t||n._focusout(e))))},_focusout:function(t){var i,n,s,a,r,l,o,u,d,f=this,g=f.options,m=t.target,h=t.type,p="focusin"===h,v="validate"===h,_=0;if("compositionstart"===h&&(f.pauseValidate=!0),"compositionend"===h&&(f.pauseValidate=!1),!f.pauseValidate&&(n=m.name&&c(m)?f.$el.find('input[name="'+m.name+'"]').get(0):m,(s=f.getField(n))&&s.rule)){if(i=s._e,s._e=h,d=s.timely,!v){if(!d||c(m)&&"click"!==h)return;if(r=s.getValue(),s.ignoreBlank&&!r&&!p)return void f.hideMsg(m);if("focusout"===h){if("change"===i)return;if(2===d||8===d){if(a=s.old,!r||!a)return;s.isValid&&!a.showOk?f.hideMsg(m):f._makeMsg(m,s,a)}}else{if(d<2&&!t.data)return;if(l=+new Date,l-(m._ts||0)<100)return;if(m._ts=l,"keyup"===h){if("input"===i)return;if(o=t.keyCode,u={8:1,9:1,16:1,32:1,46:1},9===o&&!r)return;if(o<48&&!u[o])return}p||(_=d<100?"click"===h||"SELECT"===m.tagName?0:400:d)}}g.ignore&&e(m).is(g.ignore)||(clearTimeout(s._t),_?s._t=setTimeout(function(){f._validate(m,s)},_):(v&&(s.old={}),f._validate(m,s)))}},_setClass:function(t,i){var n=e(t),s=this.options;s.bindClassTo&&(n=n.closest(s.bindClassTo)),n.removeClass(s.invalidClass+" "+s.validClass),null!==i&&n.addClass(i?s.validClass:s.invalidClass)},_showmsg:function(e,t,i){var n=this,s=e.target;n.$el.is(s)?J(t)?n.showMsg(t):"tip"===t&&n.$el.find(N+"["+O+"]",s).each(function(){n.showMsg(this,{type:t,msg:i})}):n.showMsg(s,{type:t,msg:i})},_hidemsg:function(t){var i=e(t.target);i.is(N)&&this.hideMsg(i)},_validatedField:function(t,i,n){var s=this,a=s.options,r=i.isValid=n.isValid=!!n.isValid,l=r?"valid":"invalid";n.key=i.key,n.ruleName=i._r,n.id=t.id,n.value=i.value,s.elements[i.key]=n.element=t,s.isValid=s.$el[0].isValid=r?s.isFormValid():r,r?n.type="ok":(s.submiting&&(s.errors[i.key]=n.msg),s.hasError=!0),i.old=n,U(i[l])&&i[l].call(s,t,n),U(a.validation)&&a.validation.call(s,t,n),e(t).attr(x,!r||null).trigger(l+y,[n,s]),s.$el.triggerHandler("validation",[n,s]),s.checkOnly||(s._setClass(t,n.skip||"tip"===n.type?null:r),s._makeMsg.apply(s,arguments))},_makeMsg:function(t,i,n){i.msgMaker&&(n=e.extend({},n),"focusin"===i._e&&(n.type="tip"),this[n.showOk||n.msg||"tip"===n.type?"showMsg":"hideMsg"](t,n,i))},_validatedRule:function(i,n,s,a){n=n||c.getField(i),a=a||{};var r,l,o,d,c=this,f=n._r,g=n.timely,m=9===g||8===g,h=!1;if(null===s)return c._validatedField(i,n,{isValid:!0,skip:!0}),void(n._i=0);if(s===t?o=!0:s===!0||""===s?h=!0:W(s)?r=s:J(s)?s.error?r=s.error:(r=s.ok,h=!0):h=!!s,l=n._rules[n._i],l.not&&(r=t,h="required"===f||!h),l.or)if(h)for(;n._i<n._rules.length&&n._rules[n._i].or;)n._i++;else o=!0;else l.and&&(n.isValid||(o=!0));o?h=!0:(h&&n.showOk!==!1&&(d=X(i,F),r=null===d?W(n.ok)?n.ok:r:d,!W(r)&&W(n.showOk)&&(r=n.showOk),W(r)&&(a.showOk=h)),h&&!m||(r=(u(i,n,r||l.msg||c.messages[f])||c.messages.fallback).replace(/\{0\|?([^\}]*)\}/,function(e,t){return c._getDisplay(i,n.display)||t||c.messages[0]})),h||(n.isValid=h),a.msg=r,e(i).trigger((h?"valid":"invalid")+_,[f,r])),!m||o&&!l.and||(h||n._m||(n._m=r),n._v=n._v||[],n._v.push({type:h?o?"tip":"ok":"error",msg:r||l.msg})),c._debug("log"," "+n._i+": "+f+" => "+(h||r)),(h||m)&&n._i<n._rules.length-1?(n._i++,c._checkRule(i,n)):(n._i=0,m?(a.isValid=n.isValid,a.result=n._v,a.msg=n._m||"",n.value||"focusin"!==n._e||(a.type="tip")):a.isValid=h,c._validatedField(i,n,a),delete n._m,delete n._v)},_checkRule:function(i,n){var s,a,r,l=this,u=n.key,d=n._rules[n._i],c=d.method,f=d.params;l.submiting&&l.deferred[u]||(r=n.old,n._r=c,r&&!n.must&&!d.must&&d.result!==t&&r.ruleName===c&&r.id===i.id&&n.value&&r.value===n.value?s=d.result:(a=o(i,c)||l.rules[c]||L,s=a.call(n,i,f,n),a.msg&&(d.msg=a.msg)),J(s)&&U(s.then)?(l.deferred[u]=s,n.isValid=t,!l.checkOnly&&l.showMsg(i,{type:"loading",msg:l.messages.loading},n),s.then(function(s,a,r){var o,u=P(r.responseText),c=n.dataFilter;/jsonp?/.test(this.dataType)?u=s:"{"===u.charAt(0)&&(u=e.parseJSON(u)),o=c.call(this,u,n),o===t&&(o=c.call(this,u.data,n)),d.data=this.data,d.result=n.old?o:t,l._validatedRule(i,n,o)},function(e,t){l._validatedRule(i,n,l.messages[t]||t)}).always(function(){delete l.deferred[u]})):l._validatedRule(i,n,s))},_validate:function(e,t){var i=this;if(!e.disabled&&null===X(e,j)&&(t=t||i.getField(e),t&&(t._rules||i._parse(e),t._rules)))return i._debug("info",t.key),t.isValid=!0,t.element=e,t.value=t.getValue(),t.required||t.must||t.value||c(e)?(i._checkRule(e,t),t.isValid):(i._validatedField(e,t,{isValid:!0}),!0)},_debug:function(e,t){window.console&&this.options.debug&&console[e](t)},test:function(e,i){var n,s,a,r,l=this,o=S.exec(i);return o&&(a=o[1],a in l.rules&&(r=o[2]||o[3],r=r?r.split(", "):t,s=l.getField(e,!0),s._r=a,s.value=s.getValue(),n=l.rules[a].call(s,e,r))),n===!0||n===t||null===n},_getDisplay:function(e,t){return W(t)?t:U(t)?t.call(this,e):""},_getMsgOpt:function(t,i){var n=i?i:this.options;return e.extend({type:"error",pos:d(n.msgClass),target:n.target,wrapper:n.msgWrapper,style:n.msgStyle,cls:n.msgClass,arrow:n.msgArrow,icon:n.msgIcon},W(t)?{msg:t}:t)},_getMsgDOM:function(i,n){var s,a,r,l,o=e(i);if(o.is(N)?(r=n.target||X(i,E),r&&(r=U(r)?r.call(this,i):"#"===r.charAt(0)?e(r):this.$el.find(r),r.length&&(r.is(N)?(o=r,i=r.get(0)):r.hasClass(w)?s=r:l=r)),s||(a=c(i)&&i.name||!i.id?i.name:i.id,s=(l||this.$el).find(n.wrapper+"."+w+'[for="'+a+'"]'))):s=o,!n.hide&&!s.length)if(s=e("<"+n.wrapper+">").attr({"class":w+(n.cls?" "+n.cls:""),style:n.style||t,"for":a}),l)s.appendTo(l);else if(c(i)){var u=o.parent();s.appendTo(u.is("label")?u.parent():u)}else s[n.pos&&"right"!==n.pos?"insertBefore":"insertAfter"](o);return s},showMsg:function(t,i,n){if(t){var s,a,r,l,o=this,u=o.options;if(J(t)&&!t.jquery&&!i)return void e.each(t,function(e,t){var i=o.elements[e]||o.$el.find(m(e))[0];o.showMsg(i,t)});e(t).is(N)&&(n=n||o.getField(t)),(a=(n||u).msgMaker)&&(i=o._getMsgOpt(i,n),t=(t.name&&c(t)?o.$el.find('input[name="'+t.name+'"]'):e(t)).get(0),i.msg||"error"===i.type||(r=X(t,"data-"+i.type),null!==r&&(i.msg=r)),W(i.msg)&&(l=o._getMsgDOM(t,i),!D.test(l[0].className)&&l.addClass(i.cls),6===Q&&"bottom"===i.pos&&(l[0].style.marginTop=e(t).outerHeight()+"px"),l.html(a.call(o,i))[0].style.display="",U(s=n&&n.msgShow||u.msgShow)&&s.call(o,l,i.type)))}},hideMsg:function(t,i,n){var s,a,r=this,l=r.options;t=e(t).get(0),e(t).is(N)&&(n=n||r.getField(t),n&&(n.isValid||r.reseting)&&X(t,x,null)),i=r._getMsgOpt(i,n),i.hide=!0,a=r._getMsgDOM(t,i),a.length&&(U(s=n&&n.msgHide||l.msgHide)?s.call(r,a,i.type):(a[0].style.display="none",a[0].innerHTML=""))},getField:function(e,i){var n,s,a=this;if(W(e))n=e,e=t;else{if(X(e,M))return a._parse(e);n=e.id&&"#"+e.id in a.fields||!e.name?"#"+e.id:e.name}return((s=a.fields[n])||i&&(s=new a.Field(n)))&&(s.element=e),s},setField:function(e,t){var i={};e&&(W(e)?i[e]=t:i=e,this._initFields(i))},isFormValid:function(){var e,t,i=this.fields;for(e in i)if(t=i[e],t._rules&&(t.required||t.must||t.value)&&!t.isValid)return!1;return!0},holdSubmit:function(e){this.submiting=e===t||e},cleanUp:function(){this._reset(1)},destroy:function(){this._reset(1),this.$el.off(v).removeData(p),X(this.$el[0],j,this._NOVALIDATE)}},e(window).on("beforeunload",function(){this.focus()}),e(document).on("click",":submit",function(){var e,t=this;t.form&&(e=t.getAttributeNode("formnovalidate"),(e&&null!==e.nodeValue||null!==X(t,j))&&(h=!0))}).on("focusin submit validate","form,."+k,function(t){if(null===X(this,j)){var i,n=e(this);!n.data(p)&&(i=l(this))&&(e.isEmptyObject(i.fields)?(X(this,j,j),n.off(v).removeData(p)):"focusin"===t.type?i._focusin(t):i._submit(t))}}),new a({fallback:"This field is not valid.",loading:"Validating..."}),new s({required:function(t,i){var n=this,s=P(n.value),a=!0;if(i)if(1===i.length){if(g(i[0])){if(n.rules[i[0]]&&!s&&!n.test(t,i[0]))return null}else if(!s&&!e(i[0],n.$el).length)return null}else if("not"===i[0])e.each(i.slice(1),function(){return a=s!==P(this)});else if("from"===i[0]){var r,l=n.$el.find(i[1]),o="_validated_";return a=l.filter(function(){var e=n.getField(this);return e&&!!P(e.getValue())}).length>=(i[2]||1),a?s||(r=null):r=u(l[0],n)||!1,e(t).data(o)||l.data(o,1).each(function(){t!==this&&n._validate(this)}).removeData(o),r}return a&&!!s},integer:function(e,t){var i,n="0|",s="[1-9]\\d*",a=t?t[0]:"*";switch(a){case"+":i=s;break;case"-":i="-"+s;break;case"+0":i=n+s;break;case"-0":i=n+"-"+s;break;default:i=n+"-?"+s}return i="^(?:"+i+")$",new RegExp(i).test(this.value)||this.messages.integer&&this.messages.integer[a]},match:function(t,i){if(i){var n,s,a,r,l,o,u,d=this,c=!0,g="eq";if(1===i.length?a=i[0]:(g=i[0],a=i[1]),l=m(a),o=d.$el.find(l)[0]){if(u=d.getField(o),n=d.value,s=u.getValue(),d._match||(d.$el.on("valid"+y+v,l,function(){e(t).trigger("validate")}),d._match=u._match=1),!d.required&&""===n&&""===s)return null;if(r=i[2],r&&(/^date(time)?$/i.test(r)?(n=f(n),s=f(s)):"time"===r&&(n=+n.replace(/:/g,""),s=+s.replace(/:/g,""))),"eq"!==g&&!isNaN(+n)&&isNaN(+s))return!0;switch(g){case"lt":c=+n<+s;break;case"lte":c=+n<=+s;break;case"gte":c=+n>=+s;break;case"gt":c=+n>+s;break;case"neq":c=n!==s;break;default:c=n===s}return c||J(d.messages.match)&&d.messages.match[g].replace("{1}",d._getDisplay(t,u.display||a))}}},range:function(e,t){return this.getRangeMsg(this.value,t)},checked:function(e,t){if(c(e)){var i,n,s=this;return e.name?n=s.$el.find('input[name="'+e.name+'"]').filter(function(){var e=this;return!i&&c(e)&&(i=e),!e.disabled&&e.checked}).length:(i=e,n=i.checked),t?s.getRangeMsg(n,t):!!n||u(i,s,"")||s.messages.required||!1}},length:function(e,t){var i=this.value,n=("true"===t[1]?i.replace(q,"xx"):i).length;return this.getRangeMsg(n,t,t[1]?"_2":"")},remote:function(t,i){if(i){var n,s=this,a=I.exec(i[0]),r=s._rules[s._i],l={},o="",u=a[3],d=a[2]||"POST",c=(a[1]||"").toLowerCase();return r.must=!0,l[t.name]=s.value,i[1]&&e.map(i.slice(1),function(e){var t,i;~e.indexOf("=")?o+="&"+e:(t=e.split(":"),e=P(t[0]),i=P(t[1])||e,l[e]=s.$el.find(m(i)).val())}),l=e.param(l)+o,!s.must&&r.data&&r.data===l?r.result:("cors"!==c&&/^https?:/.test(u)&&!~u.indexOf(location.host)&&(n="jsonp"),e.ajax({url:u,type:d,data:l,dataType:n}))}},filter:function(e,t){var i=this.value,n=i.replace(t?new RegExp("["+t[0]+"]","gm"):H,"");n!==i&&this.setValue(n)}}),i.config=function(t,i){function n(e,t){"rules"===e?new s(t):"messages"===e?new a(t):e in K?K[e]=t:G[e]=t}J(t)?e.each(t,n):W(t)&&n(t,i)},i.setTheme=function(t,i){J(t)?e.extend(!0,Y,t):W(t)&&J(i)&&(Y[t]=e.extend(Y[t],i))},i.load=function(t){if(t){var n,s,a,r=document,l={},o=r.scripts[0];t.replace(/([^?=&]+)=([^&#]*)/g,function(e,t,i){l[t]=i}),n=l.dir||i.dir,i.css||""===l.css||(s=r.createElement("link"),s.rel="stylesheet",s.href=i.css=n+"jquery.validator.css",o.parentNode.insertBefore(s,o)),!i.local&&~t.indexOf("local")&&""!==l.local&&(i.local=(l.local||r.documentElement.lang||"en").replace("_","-"),i.pending=1,s=r.createElement("script"),s.src=n+"local/"+i.local+".js",a="onload"in s?"onload":"onreadystatechange",s[a]=function(){s.readyState&&!/loaded|complete/.test(s.readyState)||(s=s[a]=null,delete i.pending,e(window).triggerHandler("validatorready"))},o.parentNode.insertBefore(s,o))}},function(){for(var e,t,n=document.scripts,s=n.length,a=/(.*validator(?:\.min)?.js)(\?.*(?:local|css|dir)(?:=[\w\-]*)?)?/;s--&&!t;)e=n[s],t=(e.hasAttribute?e.src:e.getAttribute("src",4)||"").match(a);t&&(i.dir=t[1].split("/").slice(0,-1).join("/")+"/",i.load(t[2]))}(),e[p]=i});
\ No newline at end of file \ No newline at end of file
/*********************************
* Themes, rules, and i18n support
* Locale: English
*********************************/
(function(factory) {
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(jQuery);
}(function($) {
/* Global configuration
*/
$.validator.config({
//stopOnError: true,
//focusCleanup: true,
//theme: 'yellow_right',
//timely: 2,
// Custom rules
rules: {
digits: [/^\d+$/, "Please enter only digits."]
,letters: [/^[a-z]+$/i, "Please enter only letters."]
,date: [/^\d{4}-\d{2}-\d{2}$/, "Please enter a valid date, format: yyyy-mm-dd"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "Please enter a valid time, between 00:00 and 23:59"]
,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "Please enter a valid email address."]
,url: [/^(https?|s?ftp):\/\/\S+$/i, "Please enter a valid URL."]
,accept: function (element, params){
if (!params) return true;
var ext = params[0],
value = $(element).val();
return (ext === '*') ||
(new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
this.renderMsg("Only accept {1} file extension.", ext.replace(/\|/g, ', '));
}
},
// Default error messages
messages: {
0: "This field",
fallback: "{0} is not valid.",
loading: "Validating...",
error: "Network Error.",
timeout: "Request timed out.",
required: "{0} is required.",
remote: "Please try another name.",
integer: {
'*': "Please enter an integer.",
'+': "Please enter a positive integer.",
'+0': "Please enter a positive integer or 0.",
'-': "Please enter a negative integer.",
'-0': "Please enter a negative integer or 0."
},
match: {
eq: "{0} must be equal to {1}.",
neq: "{0} must be not equal to {1}.",
lt: "{0} must be less than {1}.",
gt: "{0} must be greater than {1}.",
lte: "{0} must be less than or equal to {1}.",
gte: "{0} must be greater than or equal to {1}."
},
range: {
rg: "Please enter a number between {1} and {2}.",
gte: "Please enter a number greater than or equal to {1}.",
lte: "Please enter a number less than or equal to {1}.",
gtlt: "Please fill in the number of {1} to {2}.",
gt: "Please enter a number greater than {1}.",
lt: "Please enter a number less than {1}."
},
checked: {
eq: "Please check {1} items.",
rg: "Please check between {1} and {2} items.",
gte: "Please check at least {1} items.",
lte: "Please check no more than {1} items."
},
length: {
eq: "Please enter {1} characters.",
rg: "Please enter a value between {1} and {2} characters long.",
gte: "Please enter at least {1} characters.",
lte: "Please enter no more than {1} characters.",
eq_2: "",
rg_2: "",
gte_2: "",
lte_2: ""
}
}
});
/* Themes
*/
var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
$.validator.setTheme({
'simple_right': {
formClass: 'n-simple',
msgClass: 'n-right'
},
'simple_bottom': {
formClass: 'n-simple',
msgClass: 'n-bottom'
},
'yellow_top': {
formClass: 'n-yellow',
msgClass: 'n-top',
msgArrow: TPL_ARROW
},
'yellow_right': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW
},
'yellow_right_effect': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW,
msgShow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({left: '20px', opacity: 0})
.delay(100).show().stop()
.animate({left: '-4px', opacity: 1}, 150)
.animate({left: '3px'}, 80)
.animate({left: 0}, 80);
} else {
$el.css({left: 0, opacity: 1}).fadeIn(200);
}
},
msgHide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show()
.animate({left: '20px', opacity: 0}, 300, function(){
$msgbox.hide();
});
}
}
});
}));
/*********************************
* Themes, rules, and i18n support
* Locale: English
*********************************/
(function(factory) {
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(jQuery);
}(function($) {
/* Global configuration
*/
$.validator.config({
//stopOnError: true,
//focusCleanup: true,
//theme: 'yellow_right',
//timely: 2,
// Custom rules
rules: {
digits: [/^\d+$/, "Please enter only digits."]
,letters: [/^[a-z]+$/i, "Please enter only letters."]
,date: [/^\d{4}-\d{2}-\d{2}$/, "Please enter a valid date, format: yyyy-mm-dd"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "Please enter a valid time, between 00:00 and 23:59"]
,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "Please enter a valid email address."]
,url: [/^(https?|s?ftp):\/\/\S+$/i, "Please enter a valid URL."]
,accept: function (element, params){
if (!params) return true;
var ext = params[0],
value = $(element).val();
return (ext === '*') ||
(new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
this.renderMsg("Only accept {1} file extension.", ext.replace(/\|/g, ', '));
}
},
// Default error messages
messages: {
0: "This field",
fallback: "{0} is not valid.",
loading: "Validating...",
error: "Network Error.",
timeout: "Request timed out.",
required: "{0} is required.",
remote: "Please try another name.",
integer: {
'*': "Please enter an integer.",
'+': "Please enter a positive integer.",
'+0': "Please enter a positive integer or 0.",
'-': "Please enter a negative integer.",
'-0': "Please enter a negative integer or 0."
},
match: {
eq: "{0} must be equal to {1}.",
neq: "{0} must be not equal to {1}.",
lt: "{0} must be less than {1}.",
gt: "{0} must be greater than {1}.",
lte: "{0} must be less than or equal to {1}.",
gte: "{0} must be greater than or equal to {1}."
},
range: {
rg: "Please enter a number between {1} and {2}.",
gte: "Please enter a number greater than or equal to {1}.",
lte: "Please enter a number less than or equal to {1}.",
gtlt: "Please fill in the number of {1} to {2}.",
gt: "Please enter a number greater than {1}.",
lt: "Please enter a number less than {1}."
},
checked: {
eq: "Please check {1} items.",
rg: "Please check between {1} and {2} items.",
gte: "Please check at least {1} items.",
lte: "Please check no more than {1} items."
},
length: {
eq: "Please enter {1} characters.",
rg: "Please enter a value between {1} and {2} characters long.",
gte: "Please enter at least {1} characters.",
lte: "Please enter no more than {1} characters.",
eq_2: "",
rg_2: "",
gte_2: "",
lte_2: ""
}
}
});
/* Themes
*/
var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
$.validator.setTheme({
'simple_right': {
formClass: 'n-simple',
msgClass: 'n-right'
},
'simple_bottom': {
formClass: 'n-simple',
msgClass: 'n-bottom'
},
'yellow_top': {
formClass: 'n-yellow',
msgClass: 'n-top',
msgArrow: TPL_ARROW
},
'yellow_right': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW
},
'yellow_right_effect': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW,
msgShow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({left: '20px', opacity: 0})
.delay(100).show().stop()
.animate({left: '-4px', opacity: 1}, 150)
.animate({left: '3px'}, 80)
.animate({left: 0}, 80);
} else {
$el.css({left: 0, opacity: 1}).fadeIn(200);
}
},
msgHide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show()
.animate({left: '20px', opacity: 0}, 300, function(){
$msgbox.hide();
});
}
}
});
}));
/*********************************
* Themes, rules, and i18n support
* Locale: Japanese; 日本語
*********************************/
(function(factory) {
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(jQuery);
}(function($) {
/* Global configuration
*/
$.validator.config({
//stopOnError: true,
//focusCleanup: true,
//theme: 'yellow_right',
//timely: 2,
// Custom rules
rules: {
digits: [/^\d+$/, "数字だけを入力してください"]
,letters: [/^[a-z]+$/i, "手紙のみでお願いします"]
,date: [/^\d{4}-\d{2}-\d{2}$/, "有効な日付を入力してください、,フォーマット:YYYY-MM-DD"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "有効な時刻を入力してください,00:00~23:59の間"]
,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "有効なメールアドレスを入力してください"]
,url: [/^(https?|s?ftp):\/\/\S+$/i, "有効なURLを入力してください"]
,accept: function (element, params){
if (!params) return true;
var ext = params[0],
value = $(element).val();
return (ext === '*') ||
(new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
this.renderMsg("ファイル拡張子を{1}のみを受け入れる", ext.replace(/\|/g, '、'));
}
},
// Default error messages
messages: {
0: "このフィールド",
fallback: "{0}は有効ではありません",
loading: "検証プロセス...",
error: "ネットワークエラー",
timeout: "要求がタイムアウトしました",
required: "{0}は必須です",
remote: "この値が使用されている",
integer: {
'*': "整数を入力してください",
'+': "正の整数を入力してください",
'+0': "正の整数または0を入力してください",
'-': "負の整数を入力してください",
'-0': "負の整数または0を入力してください"
},
match: {
eq: "{0}と{1}と同じでなければなりません",
neq: "{0}と{1}は同じにすることはできません",
lt: "{0}未満{1}なければならない",
gt: "{0}より{1}大なければならない",
lte: "{0}小なりイコール{1}なければならない",
gte: "{0}大なりイコール{1}なければならない"
},
range: {
rg: "{1}~{2}の数を入力してください",
gte: "{1}以上の数を入力してください",
lte: "{1}以下の数を入力してください",
gtlt: "{1}~{2}の間の数を入力してください",
gt: "{1}より大きい数を入力してください",
lt: "{1}より小きい数を入力してください"
},
checked: {
eq: "{1}項目を選択してください",
rg: "{1}から{2}の項目を選択してください",
gte: "少なくとも{1}の項目を選択してください",
lte: "{1}の項目まで選択してください"
},
length: {
eq: "{1}文字を入力してください",
rg: "{1}文字から{2}文字までの値を入力してください",
gte: "{1}文字以上で入力してください",
lte: "{1}文字以内で入力してください",
eq_2: "",
rg_2: "",
gte_2: "",
lte_2: ""
}
}
});
/* Themes
*/
var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
$.validator.setTheme({
'simple_right': {
formClass: 'n-simple',
msgClass: 'n-right'
},
'simple_bottom': {
formClass: 'n-simple',
msgClass: 'n-bottom'
},
'yellow_top': {
formClass: 'n-yellow',
msgClass: 'n-top',
msgArrow: TPL_ARROW
},
'yellow_right': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW
},
'yellow_right_effect': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW,
msgShow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({left: '20px', opacity: 0})
.delay(100).show().stop()
.animate({left: '-4px', opacity: 1}, 150)
.animate({left: '3px'}, 80)
.animate({left: 0}, 80);
} else {
$el.css({left: 0, opacity: 1}).fadeIn(200);
}
},
msgHide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show()
.animate({left: '20px', opacity: 0}, 300, function(){
$msgbox.hide();
});
}
}
});
}));
/*********************************
* Themes, rules, and i18n support
* Locale: Chinese; 中文
*********************************/
(function(factory) {
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(jQuery);
}(function($) {
/* Global configuration
*/
$.validator.config({
//stopOnError: true,
//focusCleanup: true,
//theme: 'yellow_right',
//timely: 2,
// Custom rules
rules: {
digits: [/^\d+$/, "请填写数字"]
,letters: [/^[a-z]+$/i, "请填写字母"]
,date: [/^\d{4}-\d{2}-\d{2}$/, "请填写有效的日期,格式:yyyy-mm-dd"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "请填写有效的时间,00:00到23:59之间"]
,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "请填写有效的邮箱"]
,url: [/^(https?|s?ftp):\/\/\S+$/i, "请填写有效的网址"]
,qq: [/^[1-9]\d{4,}$/, "请填写有效的QQ号"]
,IDcard: [/^\d{6}(19|2\d)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)?$/, "请填写正确的身份证号码"]
,tel: [/^(?:(?:0\d{2,3}[\- ]?[1-9]\d{6,7})|(?:[48]00[\- ]?[1-9]\d{6}))$/, "请填写有效的电话号码"]
,mobile: [/^1[3-9]\d{9}$/, "请填写有效的手机号"]
,zipcode: [/^\d{6}$/, "请检查邮政编码格式"]
,chinese: [/^[\u0391-\uFFE5]+$/, "请填写中文字符"]
,username: [/^\w{3,12}$/, "请填写3-12位数字、字母、下划线"]
,password: [/^[\S]{6,16}$/, "请填写6-16位字符,不能包含空格"]
,accept: function (element, params){
if (!params) return true;
var ext = params[0],
value = $(element).val();
return (ext === '*') ||
(new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
this.renderMsg("只接受{1}后缀的文件", ext.replace(/\|/g, ','));
}
},
// Default error messages
messages: {
0: "此处",
fallback: "{0}格式不正确",
loading: "正在验证...",
error: "网络异常",
timeout: "请求超时",
required: "{0}不能为空",
remote: "{0}已被使用",
integer: {
'*': "请填写整数",
'+': "请填写正整数",
'+0': "请填写正整数或0",
'-': "请填写负整数",
'-0': "请填写负整数或0"
},
match: {
eq: "{0}与{1}不一致",
neq: "{0}与{1}不能相同",
lt: "{0}必须小于{1}",
gt: "{0}必须大于{1}",
lte: "{0}不能大于{1}",
gte: "{0}不能小于{1}"
},
range: {
rg: "请填写{1}到{2}的数",
gte: "请填写不小于{1}的数",
lte: "请填写最大{1}的数",
gtlt: "请填写{1}到{2}之间的数",
gt: "请填写大于{1}的数",
lt: "请填写小于{1}的数"
},
checked: {
eq: "请选择{1}项",
rg: "请选择{1}到{2}项",
gte: "请至少选择{1}项",
lte: "请最多选择{1}项"
},
length: {
eq: "请填写{1}个字符",
rg: "请填写{1}到{2}个字符",
gte: "请至少填写{1}个字符",
lte: "请最多填写{1}个字符",
eq_2: "",
rg_2: "",
gte_2: "",
lte_2: ""
}
}
});
/* Themes
*/
var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
$.validator.setTheme({
'simple_right': {
formClass: 'n-simple',
msgClass: 'n-right'
},
'simple_bottom': {
formClass: 'n-simple',
msgClass: 'n-bottom'
},
'yellow_top': {
formClass: 'n-yellow',
msgClass: 'n-top',
msgArrow: TPL_ARROW
},
'yellow_right': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW
},
'yellow_right_effect': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW,
msgShow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({left: '20px', opacity: 0})
.delay(100).show().stop()
.animate({left: '-4px', opacity: 1}, 150)
.animate({left: '3px'}, 80)
.animate({left: 0}, 80);
} else {
$el.css({left: 0, opacity: 1}).fadeIn(200);
}
},
msgHide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show()
.animate({left: '20px', opacity: 0}, 300, function(){
$msgbox.hide();
});
}
}
});
}));
/*********************************
* Themes, rules, and i18n support
* Locale: Chinese; 中文; TW (Taiwan)
*********************************/
(function(factory) {
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(jQuery);
}(function($) {
/* Global configuration
*/
$.validator.config({
//stopOnError: true,
//focusCleanup: true,
//theme: 'yellow_right',
//timely: 2,
// Custom rules
rules: {
digits: [/^\d+$/, "請填寫數字"]
,letters: [/^[a-z]+$/i, "請填寫字母"]
,date: [/^\d{4}-\d{2}-\d{2}$/, "請填寫有效的日期,格式:yyyy-mm-dd"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "請填寫有效的時間,00:00到23:59之間"]
,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "請填寫有效的電郵"]
,url: [/^(https?|s?ftp):\/\/\S+$/i, "請填寫有效的網址"]
,accept: function (element, params){
if (!params) return true;
var ext = params[0],
value = $(element).val();
return (ext === '*') ||
(new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
this.renderMsg("只接受{1}後綴的文件", ext.replace(/\|/g, ','));
}
},
// Default error messages
messages: {
0: "此處",
fallback: "{0}格式不正確",
loading: "正在驗證...",
error: "網絡異常",
timeout: "請求超時",
required: "{0}不能為空",
remote: "{0}已被使用",
integer: {
'*': "請填寫整數",
'+': "請填寫正整數",
'+0': "請填寫正整數或0",
'-': "請填寫負整數",
'-0': "請填寫負整數或0"
},
match: {
eq: "{0}與{1}不一致",
neq: "{0}與{1}不能相同",
lt: "{0}必須小於{1}",
gt: "{0}必須大於{1}",
lte: "{0}不能大於{1}",
gte: "{0}不能小於{1}"
},
range: {
rg: "請填寫{1}到{2}的數",
gte: "請填寫不小於{1}的數",
lte: "請填寫最大{1}的數",
gtlt: "請填寫{1}到{2}之間的數",
gt: "請填寫大於{1}的數",
lt: "請填寫小於{1}的數"
},
checked: {
eq: "請選擇{1}項",
rg: "請選擇{1}到{2}項",
gte: "請至少選擇{1}項",
lte: "請最多選擇{1}項"
},
length: {
eq: "請填寫{1}個字符",
rg: "請填寫{1}到{2}個字符",
gte: "請至少填寫{1}個字符",
lte: "請最多填寫{1}個字符",
eq_2: "",
rg_2: "",
gte_2: "",
lte_2: ""
}
}
});
/* Themes
*/
var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
$.validator.setTheme({
'simple_right': {
formClass: 'n-simple',
msgClass: 'n-right'
},
'simple_bottom': {
formClass: 'n-simple',
msgClass: 'n-bottom'
},
'yellow_top': {
formClass: 'n-yellow',
msgClass: 'n-top',
msgArrow: TPL_ARROW
},
'yellow_right': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW
},
'yellow_right_effect': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW,
msgShow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({left: '20px', opacity: 0})
.delay(100).show().stop()
.animate({left: '-4px', opacity: 1}, 150)
.animate({left: '3px'}, 80)
.animate({left: 0}, 80);
} else {
$el.css({left: 0, opacity: 1}).fadeIn(200);
}
},
msgHide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show()
.animate({left: '20px', opacity: 0}, 300, function(){
$msgbox.hide();
});
}
}
});
}));
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!