the use of jQuery validation framework

Plug-in Address: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Download: http://jquery.bassistance.de/validate/jquery.validate.zip

Demo: http://jquery.bassistance.de/validate/demo/

$ (Document). Ready (function () (

/ * Set default attributes * /
$. Validator.setDefaults ((
submitHandler: function (form) (form.submit ();)
));

/ / Two byte characters
jQuery.validator.addMethod ("byteRangeLength", function (value, element, param) (
var length = value.length;
for (var i = 0; i <value.length; i + +) (
if (value.charCodeAt (i)> 127) (
length + +;
)
)
return this.optional (element) | | (length> = param [0] & & length <= param [1]);
), "Please be sure to enter the value in between 3-15 bytes (1 byte characters count 2)");

/ * Additional custom authentication method * /
/ / ID number verification
jQuery.validator.addMethod ("isIdCardNo", function (value, element) (
return this.optional (element) | | isIdCardNo (value);
), "Please enter your ID number correctly");

/ / Character verification
jQuery.validator.addMethod ("userName", function (value, element) (
return this.optional (element) | | / ^ [\ u0391-\ uFFE5 \ w ]+$/. test (value);
), "User name can only include Chinese characters, English letters, numbers and underscores");

/ / Mobile phone number validation
jQuery.validator.addMethod ("isMobile", function (value, element) (
var length = value.length;
return this.optional (element) | | (length == 11 & & /^((( 13 [0-9] (1)) | (15 [0-9] (1))) + \ d (8)) $ /. test (value));
), "Please enter your phone number correct");

/ / Phone number validation
jQuery.validator.addMethod ("isPhone", function (value, element) (
var tel = / ^ (\ d (3,4 }-?)? \ d (7,9) $ / g;
return this.optional (element) | | (tel.test (value));
), "Please enter your phone number correct");

/ / Postal Code authentication
jQuery.validator.addMethod ("isZipCode", function (value, element) (
var tel = / ^ [0-9] (6) $ /;
return this.optional (element) | | (tel.test (value));
), "Please correctly fill in your zip code");

$ (RegFrom). Validate ((
/ * Set the validation rules * /
rules: (
userName: (
required: true,
userName: true,
byteRangeLength: [3,15]
)
password: (
required: true,
minLength: 5
)
repassword: (
required: true,
minLength: 5,
equalTo: "# password"
)
question: (
required: true
)
answer: (
required: true
)
realName: (
required: true
)
cardNumber: (
isIdCardNo: true
)
mobilePhone: (
isMobile: true
)
phone: (
isPhone: true
)
email: (
required: true,
email: true
)
zipCode: (
isZipCode: true
)
)
/ * Set error message * /
messages: (
userName: (
required: "Please fill in the user name"
byteRangeLength: "User name must be between 3-15 characters (a Chinese character count two characters)"
)
password: (
required: "Please fill in the password"
minlength: jQuery.format ("Enter (0).")
)
repassword: (
required: "Please confirm your password"
equalTo: "not the same password twice"
)
question: (
required: "Please enter your password prompt question"
)
answer: (
required: "Please fill in the answer to your password prompt"
)
realName: (
required: "Please fill in your real name"
)
email: (
required: "Please enter an Email address"
email: "Please enter a valid Email address"
)
)
/ * Error message display position * /
errorPlacement: function (error, element) (
error.appendTo (element.parent ());
)
/ * Verify that the processing time of the adoption * /
success: function (label) (
/ / Set as text for IE
label.html (""). addClass ("checked");
)
/ * Gets the focus does not verify * /
focusInvalid: false,
onkeyup: false
));

/ / Input box gets the focus, style settings
$ ('Input'). Focus (function () (
if ($ (this). is (": text") | | $ (this). is (": password"))
$ (This). AddClass ('focus');
if ($ (this). hasClass ('have_tooltip')) (
$ (This). Parent (). Parent (). RemoveClass ('field_normal'). AddClass ('field_focus');
)
));

/ / Input box loses focus, the style settings
$ ('Input'). Blur (function () (
$ (This). RemoveClass ('focus');
if ($ (this). hasClass ('have_tooltip')) (
$ (This). Parent (). Parent (). RemoveClass ('field_focus'). AddClass ('field_normal');
)
));
));

分类:Web 时间:2010-03-29 人气:380
分享到:
blog comments powered by Disqus

相关文章

  • jQuery: how to plug in the code page and the custom alias 2010-08-17

    As we all know, jQuery is a library with the $ symbol as an alias, but is and has been using other types of libraries, other libraries are also useful in the $ symbol as an alias, this function will lead to conflict. Therefore, more time is recommend

  • jquery validation Chinese problem solving 2010-05-10

    <script type="text/javascript" src="/js/jquery-1.3.2.min.js"> </ script> <script type="text/javascript" src="/js/jquery.validate.js"> </ script> <script type="text/javascript">

  • Chinese garbled jQuery form validation issue 2010-07-22

    Chinese garbled jQuery form validation issue Problem description: Form using jQuery for client-side validation, expected when the input is empty, in the text box behind the display to the corresponding Chinese tips. The results appear garbled, but wh

  • Regular expression matching Chinese characters, Ctrl + F of the Gospel! 2010-03-23

    Chinese characters matching the regular expression: [\ u4e00-\ u9fa5] Comment: The match really is a headache for the Chinese thing, with this expression on the much easier to handle Matching double-byte characters (including the Chinese characters i

  • Tablesorter Chinese characters to solve sorting and scope 2010-08-31

    tablesorter jQuery plug-in is a relatively good form sort plug-ins, I think we all used or have heard, I am here not too much description, and more information can look at the official website: http://tablesorter.com/ Docs / (more complete one of the

  • Abbreviated Chinese characters Search 2010-03-29

    public class ChineseTools ( / ** * 1 GB storage of the different pronunciations of Chinese characters starting area code * / static final int [] secPosValueList = ( 1601, 1637, 1833, 2078, 2274, 2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3

  • Chinese characters into pinyin 2010-03-26

    <? /* * The Chinese characters, words into Chinese Pinyin and Bopomofo abbreviations , If : Deep development >shenfazhan, sfz * Note : The file encoding must be gb2312 */ $d=array( array("a",-20319), array("ai",-20317), array(&qu

  • Chinese characters in the address bar pass 2010-04-14

    /* Filename: encode.js Function: encodechinese(uri) - The string ( Including Chinese ) Converts URLs in the passed string , The receiver need to use the Base64 decoded and then on the application/x-www-form-urlencoded Decodes a string . utf16to8(str)

  • python determine whether Chinese characters 2010-04-27

    Transfer from http://xiudaima.appspot.com/ """ Determine whether Unicode code into Chinese characters . """ def is_cn_char(i): return 0x4e00<=ord(i)<0x9fa6 def is_cn_or_en(i): o = ord(i) return o<128 or 0x4e00<=o&

  • Chinese characters Mysql Data too long for column 'name' at row 1 2010-05-09

    INSERT INTO Shenzhen (ItemId, Title, City, PostCode, X, Y, en_title) VALUES (1720, 'Shenzhen News-Shenzhen Post', 'Shenzhen','', 114311218, 22598236, '2 ') Just doing an insert operation when prompted 1046 - Data too long for column 'Title' at row 1

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.338 (s). 12 q(s)