This commit is contained in:
2025-04-26 11:07:05 +08:00
commit abf553c41b
4942 changed files with 930993 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
{
"name": "nice-validator",
"description": "Simple, smart and pleasant verification solution.",
"moduleType": [
"amd",
"node",
"globals"
],
"keywords": [
"jquery",
"validation",
"form",
"validator",
"validate",
"nice-validator",
"jquery-plugin"
],
"authors": [
"Jony Zhang <niceue@live.com>"
],
"license": "MIT",
"homepage": "https://github.com/niceue/nice-validator",
"repository": {
"type": "git",
"url": "https://github.com/niceue/nice-validator.git"
},
"main": "dist/jquery.validator.js",
"dependencies": {
"jquery": ">=1.7"
},
"ignore": [
".*",
"src",
"test",
"gulpfile.js",
"*.json",
"*.md",
"*.yml",
"!README.md"
],
"version": "1.1.5",
"_release": "1.1.5",
"_resolution": {
"type": "version",
"tag": "1.1.5",
"commit": "76d0e5d7b098ce7cf0f4fd6bd8662cba8a366497"
},
"_source": "https://github.com/niceue/validator.git",
"_target": "~1.1.1",
"_originalSource": "nice-validator"
}

View File

@@ -0,0 +1,106 @@
# nice-validator
[![Build Status](https://travis-ci.org/niceue/nice-validator.svg)](https://travis-ci.org/niceue/nice-validator)
[![Downloads](https://img.shields.io/github/downloads/niceue/nice-validator/total.svg)](https://github.com/niceue/nice-validator/releases)
[![Version](https://img.shields.io/npm/v/nice-validator.svg)](https://www.npmjs.com/package/nice-validator)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](http://niceue.com/licenses/MIT-LICENSE.txt)
Simple, smart and pleasant validation solution.
[Download](https://github.com/niceue/nice-validator/releases) the latest release
or install package via [npm](https://www.npmjs.com/) or [bower](http://bower.io/)
```bash
$ npm install nice-validator
```
```bash
$ bower install nice-validator
```
## Getting started
#### 1. Include [jQuery 1.7+](http://jquery.com)
#### 2. Include nice-validator
width `<script>` tag:
```html
<script src="path/to/nice-validator/jquery.validator.min.js?local=en"></script>
```
via [webpack](http://webpack.github.io/)
```javascript
require('nice-validator')
require('nice-validator/local/zh-CN')
```
via module loader [Requirejs](http://requirejs.org/):
```javascript
requirejs.config({
paths: {
jquery: 'http://cdn.jsdelivr.net/jquery/1.12.3/jquery.min',
validator: 'path/to/nice-validator/local/en'
},
shim: {
validator: ['path/to/nice-validator/jquery.validator.js?css']
}
});
require(['validator']);
```
#### 3. Config rules
```html
<form id="form1">
<input type="text" name="field1" data-rule="required;email;remote(checkEmail.php)">
<input type="text" name="field2" data-rule="required;length(6~16)">
<input type="text" name="field3" data-rule="match(field2)">
<input type="text" name="field4" data-rule="range(0~100)" id="field4">
<input type="text" name="field5" data-rule="required(#field4:filled)">
<input type="text" name="field6" data-rule="required; mobile|email;" data-msg="Please fill mobile or email">
<input type="text" name="field7"
data-rule="required; !digits; length(6~)"
data-msg-digits="Please not fill pure digits"
data-msg-length="Please fill at least {1} characters.">
<input type="checkbox" name="field8" data-rule="checked">
... yadda yadda ...
</form>
```
It has started to work when you use native submitting.
#### 4. Handle submit (Optional)
```javascript
$("#form1").on('valid.form', function(){
// You can do something, then submit form by native
// this.submit();
// or submit form by ajax
$.post("path/to/server", $(this).serialize())
.done(function(d){
// do something
});
});
```
## Documention
- [English](https://github.com/niceue/nice-validator/wiki/Getting-Started)
- [简体中文](http://validator.niceue.com/)
## Browser Support
* IE6+
* Chrome
* Safari 4+
* Firefox 9+
* Opera
## Bugs / Contributions
- [Report a bug](https://github.com/niceue/nice-validator/issues)
- To contribute or send an idea, github message me or fork the project
## Build
Install dependencies:
```bash
$ npm install -g gulp
$ npm install
```
Run test and build:
```bash
$ gulp
```
## License
nice-validator is available under the terms of the [MIT License](http://niceue.com/licenses/MIT-LICENSE.txt).

View File

@@ -0,0 +1,41 @@
{
"name": "nice-validator",
"description": "Simple, smart and pleasant verification solution.",
"moduleType": [
"amd",
"node",
"globals"
],
"keywords": [
"jquery",
"validation",
"form",
"validator",
"validate",
"nice-validator",
"jquery-plugin"
],
"authors": [
"Jony Zhang <niceue@live.com>"
],
"license": "MIT",
"homepage": "https://github.com/niceue/nice-validator",
"repository": {
"type": "git",
"url": "https://github.com/niceue/nice-validator.git"
},
"main": "dist/jquery.validator.js",
"dependencies": {
"jquery": ">=1.7"
},
"ignore": [
".*",
"src",
"test",
"gulpfile.js",
"*.json",
"*.md",
"*.yml",
"!README.md"
]
}

View File

@@ -0,0 +1,38 @@
body {font: 100%/1.5 "Helvetica", "Arial", "Microsoft Yahei";}
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea,
[contenteditable] {
width:250px; height:26px; line-height: 26px;
padding: 0;
padding-left: 5px;
box-sizing: border-box;
border: 1px solid #d9d9d9;
border-top: 1px solid #c0c0c0;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus,
[contenteditable]:focus {
outline: none;
border-color: #1E90FF;
box-shadow: 0 0 4px rgba(30,144,255,.5);
}
[contenteditable] {display: inline-block; overflow: hidden; white-space: nowrap;}
.form {max-width:600px;margin: 40px 20px;}
.form h3 {font-weight: 400; margin: 1.2em 0 .8em;}
.form p {margin: .8em 0;}
.form .note {color:#ccc; font-weight:200; font-size: .9em}
.form-item {margin: .8em 0;}
.form-item .label {display:block; margin:10px 0 2px; font-size:14px;}
.form-item .n-invalid {border:1px solid #c00;}
.form-item .n-invalid:focus {outline: none; border-color:#c00; box-shadow: 0 0 4px rgba(192,0,0,0.5);}
.form-item button {padding:5px 20px;}
.form-item .input-sm {width:120px;}

View File

@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Full Example</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form class="form" data-validator-option="{timely:2, focusCleanup:true}">
<div class="form-item">
<label class="label">Username</label>
<input type="text" name="username"
data-rule="required;username;"
data-rule-username="[/^[\w\d]{3,12}$/, 'Please enter 3-12 digits, letters, underscores']"
data-tip="You can use letters, numbers and periods"
>
</div>
<div class="form-item">
<label class="label">Password</label>
<input type="password" name="pwd"
data-rule="Password: required; length(8~16)"
data-tip="Please fill in at least eight characters"
>
</div>
<div class="form-item">
<label class="label">Verify Password</label>
<input type="password" name="pwdAgain" data-rule="Verify Password: required; match(pwd)">
</div>
<div class="form-item">
<label class="label">Gender</label>
<select name="gender" data-rule="required">
<option value="">select ...</option>
<option value="1">Male</option>
<option value="2">Female</option>
<option value="3">Other</option>
</select>
</div>
<div class="form-item">
<label class="label">Email</label>
<input type="text" name="email" data-rule="required;email">
</div>
<div class="form-item">
<label class="label">Interest</label>
<label><input type="checkbox" name="interest" data-rule="checked">sports</label>
<label><input type="checkbox" name="interest">movie</label>
<label><input type="checkbox" name="interest">game</label>
</div>
<div class="form-item">
<label class="label">Note</label>
<textarea data-rule="required;"></textarea>
</div>
<div class="form-item">
<label><input type="checkbox" id="agree_arguments" data-rule="checked">I agree to the service agreement.</label>
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.min.js?local=en"></script>
</body>
</html>

View File

@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Load By RequireJS</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form id="form1" class="form">
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<input type="password" name="password" data-rule="required;" placeholder="Password">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/requirejs/2.1.22/require.min.js"></script>
<script>
requirejs.config({
baseUrl: '../',
paths: {
jquery: 'https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min',
validator: 'dist/local/zh-CN'
},
shim: {
validator: ['../dist/jquery.validator.js?css']
}
});
// Way 1: Use plugin methods
require(['jquery', 'validator'], function($){
$('#form1').validator({
timely: 2,
stopOnError: true,
theme: 'yellow_right'
});
});
// Way 2: Just include nice-validator
// require(['validator']);
// Way 3: Define a module dependency nice-validator
// define('some-module', ['jquery', 'validator'], function($){
// // some code
// });
</script>
</body>
</html>

View File

@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Load in Global</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form class="form" data-validator-option="{timely:2}">
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<input type="password" name="password" data-rule="required;" placeholder="Password">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
</body>
</html>

View File

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Display</title>
<link rel="stylesheet" href="demo.css">
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
</head>
<body>
<form class="form" data-validator-option="{timely:2}">
<h3>Default behavior</h3>
<p class="note">data-rule="required"</p>
<div class="form-item">
<input type="text" name="name" data-rule="required">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2}">
<h3>Set the field display by rule string</h3>
<p class="note">data-rule="Name: required"</p>
<div class="form-item">
<input type="text" name="name" data-rule="Name:required">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2}">
<h3>Set the field display by bind display</h3>
<p class="note">data-rule="required" data-display="Name"</p>
<div class="form-item">
<input type="text" name="name" data-rule="required" data-display="Name">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" id="form4">
<h3>Dynamic get field display.</h3>
<div class="form-item">
<label class="label">Name</label>
<input type="text" name="name" data-rule="required">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script>
$('#form4').validator({
timely:2,
display: function(el) {
return $(el).closest('.form-item').find('label.label').text();
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Target</title>
<link rel="stylesheet" href="demo.css">
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
</head>
<body>
<form class="form" data-validator-option="{timely:2, theme:'yellow_right'}">
<h3>Target to other input</h3>
<div class="form-item">
<label class="label">Name</label>
<input type="text" class="input-sm" name="firstName" data-target="#lastName" data-rule="required" placeholder="First Name">
<input type="text" class="input-sm" name="lastName" id="lastName" data-rule="required" placeholder="Last Name">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, theme:'simple_right'}">
<h3>Target to "msg-box"</h3>
<div class="form-item">
<input type="text" name="name" data-rule="Name:required" data-target="#holdMsg" placeholder="Name">
</div>
<div class="form-item">
<button type="submit">Submit</button>
<span class="msg-box" id="holdMsg"></span>
</div>
</form>
<form class="form" data-validator-option="{timely:2}">
<h3>Target to a container</h3>
<div id="msgContainer"></div>
<div class="form-item">
<input type="text" name="name" data-rule="Name:required" data-target="#msgContainer">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" id="form4">
<h3>Dynamic message place.</h3>
<div class="form-item">
<label class="label">Name</label>
<input type="text" class="input-sm" name="firstName" data-rule="required" placeholder="First Name">
<input type="text" class="input-sm" name="lastName" data-rule="required" placeholder="Last Name">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script>
$('#form4').validator({
timely:2,
stopOnError: true,
display: function(input) {
return $(input).attr('placeholder');
},
target: function(input) {
var $formitem = $(input).closest('.form-item'),
$msgbox = $formitem.find('span.msg-box');
if (!$msgbox.length) {
$msgbox = $('<span class="msg-box"></span>').appendTo($formitem);
}
return $msgbox;
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Themes</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form class="form" data-validator-option="{timely:2}">
<h3>Default theme</h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<input type="password" name="password" data-rule="required;length(6~16)" placeholder="Password">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, theme:'yellow_right'}">
<h3>Tip on right</h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<input type="password" name="password" data-rule="required;length(6~16)" placeholder="Password">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, theme:'yellow_right_effect'}">
<h3>Tip with an effect</h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, theme:'yellow_top'}">
<h3>Tip on top</h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, theme:'simple_right', showOk:''}">
<h3>Simple message on right</h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, theme:'simple_bottom'}">
<h3>Simple message on bottom</h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.min.js?local=en"></script>
</body>
</html>

View File

@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Timely</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form class="form" data-validator-option="{timely:0}">
<h3>timely: 0 <span class="note">(only validation on submit)</span></h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:1, focusCleanup:true}">
<h3>timely: 1 <span class="note">(default, validation on blur)</span></h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:2, focusCleanup:true}">
<h3>timely: 2 <span class="note">(validation on input)</span></h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:3, focusCleanup:true}">
<h3>timely: 3 <span class="note">(validation on input and blur)</span></h3>
<p>Unlike "timely:2", when focusout an empty field.</p>
<div class="form-item">
<input type="text" name="user[email]"
data-rule="required;email"
data-tip="Please fill a email." placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:8, focusCleanup:true, theme:'yellow_right'}">
<h3>timely: 8 <span class="note">(validation on input, show every rule message)</span></h3>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{timely:9, focusCleanup:true, theme:'yellow_right'}">
<h3>timely: 9 <span class="note">(validation on input and blur, show every rule message)</span></h3>
<p>Unlike "timely:8", when focusout an empty field.</p>
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form class="form" data-validator-option="{focusCleanup:true, theme:'yellow_right'}">
<h3>Set different timely value in one form</h3>
<div class="form-item">
<input type="text" name="field0" data-rule="required;length(6~)" data-timely="0" placeholder="timely:0, submit">
</div>
<div class="form-item">
<input type="text" name="field1" data-rule="required;length(6~)" data-timely="1" placeholder="timely:1, submit / focusout" data-ok="">
</div>
<div class="form-item">
<input type="text" name="field2" data-rule="required;length(6~)" data-timely="2" placeholder="timely:2, submit / input" data-tip="Just a test!">
</div>
<div class="form-item">
<input type="text" name="field3" data-rule="required;length(6~)" data-timely="3" placeholder="timely:3, submit / input / focusout">
</div>
<div class="form-item">
<input type="text" name="field8" data-rule="required;length(6~)" data-timely="8" placeholder="timely:8, submit / input">
</div>
<div class="form-item">
<input type="text" name="field9" data-rule="required;length(6~)" data-timely="9" placeholder="timely:9, submit / input / focusout">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
</body>
</html>

View File

@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Required By Condition</title>
<link rel="stylesheet" href="demo.css">
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.min.js?local=en"></script>
</head>
<body>
<form id="form1" class="form" data-validator-option="{timely:3,focusCleanup:true}">
<h3>required( dependency-expression )</h3>
<div class="form-item">
<label for="isCompany"><input type="checkbox" id="isCompany" checked>Company</label>
</div>
<div class="form-item">
<input type="text" name="companyName" data-rule="required(#isCompany:checked)">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<form id="form2" class="form">
<h3>required( dependency-callback )</h3>
<div class="form-item">
<label><input type="checkbox" id="isPersonal" checked>Personal</label>
</div>
<div class="form-item">
<input type="text" name="email">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script>
$('#form2').validator({
timely: 3,
focusCleanup: true,
rules: {
isPersonal: function() {
return $('#isPersonal').prop('checked');
}
},
fields: {
email: 'required(isPersonal); email'
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Required From Group</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form class="form" data-validator-option="{timely:2,showOk:''}">
<div class="form-item">
<input type="text" class="contact" name="mobile" placeholder="手机号"
data-rule="required(from, .contact); mobile"
data-msg-required="请至少填写一种联系方式">
</div>
<div class="form-item">
<input type="text" class="contact" name="tel" placeholder="电话"
data-rule="required(from, .contact); tel">
</div>
<div class="form-item">
<input type="text" class="contact" name="email" placeholder="邮箱"
data-rule="required(from, .contact); email">
</div>
<div class="form-item">
<button type="submit">提交</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.min.js?local=zh-CN"></script>
</body>
</html>

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Contenteditable</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form id="form1" class="form" data-validator-option="{timely:2}">
<div class="form-item">
<div contenteditable id="email" data-rule="required;email"></div>
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
<script>
$('#form1').on('valid.form', function(){
alert('ok')
});
</script>
</body>
</html>

View File

@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Used With Bootstrap</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
<style>
.n-bootstrap .msg-wrap {font-size: 14px; margin-top: 3px}
</style>
</head>
<body>
<div class="container" style="margin-top:30px">
<div class="col-md-5 col-md-offset-2">
<form id="form1" data-validator-option="{theme:'bootstrap', timely:2, stopOnError:true}">
<div class="form-group">
<label class="control-label">Username</label>
<input type="text" class="form-control" name="username"
data-rule="required;username;"
data-rule-username="[/[\w\d]{4,30}/, 'Please enter 3-12 digits, letters, underscores']"
data-tip="You can use letters, numbers and periods"
>
</div>
<div class="form-group">
<label class="control-label">Password</label>
<input type="password" class="form-control" name="pwd"
data-rule="Password: required; length(8~16)"
data-tip="Please fill in at least eight characters"
>
</div>
<div class="form-group">
<label class="control-label">Verify Password</label>
<input type="password" class="form-control" name="pwdAgain" data-rule="Verify Password: required; match(pwd)">
</div>
<div class="form-group">
<label class="control-label">Gender</label>
<select class="form-control" name="gender" data-rule="required">
<option value="">select ...</option>
<option value="1">Male</option>
<option value="2">Female</option>
<option value="3">Other</option>
</select>
</div>
<div class="form-group">
<label class="control-label">Email</label>
<input type="text" class="form-control" name="email" data-rule="required;email">
</div>
<div class="form-group">
<label class="control-label">Interest</label>
<div class="">
<label class="checkbox-inline"><input type="checkbox" name="interest" data-rule="checked">sports</label>
<label class="checkbox-inline"><input type="checkbox" name="interest">movie</label>
<label class="checkbox-inline"><input type="checkbox" name="interest">game</label>
</div>
</div>
<div class="form-group">
<label class="control-label">Note</label>
<textarea class="form-control" data-rule="required;"></textarea>
</div>
<div class="form-group">
<label class="checkbox-inline"><input type="checkbox" id="agree_arguments" data-rule="checked">I agree to the service agreement.</label>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">reset</button>
</div>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
<script>
$(function(){
// Custom theme
$.validator.setTheme('bootstrap', {
validClass: 'has-success',
invalidClass: 'has-error',
bindClassTo: '.form-group',
formClass: 'n-default n-bootstrap',
msgClass: 'n-right'
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Used With jQuery Form Plugin</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form id="form1" class="form" data-validator-option="{timely:2, focusCleanup:true}">
<div class="form-item">
<label class="label">Username</label>
<input type="text" name="username"
data-rule="required; username;"
data-rule-username="[/[\w\d]{4,30}/, 'Please enter 3-12 digits, letters, underscores']"
data-tip="You can use letters, numbers and periods"
>
</div>
<div class="form-item">
<label class="label">Password</label>
<input type="password" name="pwd"
data-rule="Password: required; length(8~16)"
data-tip="Please fill in at least eight characters"
>
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.form/3.51/jquery.form.min.js"></script>
<script src="../dist/jquery.validator.js?local=en"></script>
<script>
$(function(){
// See: http://malsup.com/jquery/form/#api
// Way 1: use .ajaxForm() directly
$('#form1').ajaxForm({
url: 'http://www.mocky.io/v2/5703d5b52700006b2606b00e',
success: function(d) {
alert(d.message)
}
});
// Way 2: use .ajaxSubmit() after valid form
/*$('#form1').on('valid.form', function(){
$(this).ajaxSubmit({
url: 'http://www.mocky.io/v2/5703d5b52700006b2606b00e',
success: function(d) {
alert(d.message)
}
});
});*/
// Way 3: ditto
/*$('#form1').validator({
valid: function(){
$(this).ajaxSubmit({
url: 'http://www.mocky.io/v2/5703d5b52700006b2606b00e',
success: function(d) {
alert(d.message)
}
});
}
});*/
});
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,269 @@
.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;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,137 @@
/*********************************
* 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();
});
}
}
});
}));

View File

@@ -0,0 +1,137 @@
/*********************************
* 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();
});
}
}
});
}));

View File

@@ -0,0 +1,145 @@
/*********************************
* 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();
});
}
}
});
}));

View File

@@ -0,0 +1,137 @@
/*********************************
* 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();
});
}
}
});
}));