jquery Form Verification Plug-in dform usage instructions

Source: Internet
Author: User
Tags extend preg regular expression

How to load:

The code is as follows Copy Code

<script type= "Text/javascript" charset= "utf-8″src=". /jquery.js "></script>

<script type= "Text/javascript" charset= "utf-8″src=". /dform.js "></script>

<script type= "Text/javascript" charset= "utf-8″>

$ (document). Ready (function () {

$.fn.extend ({' Dform ':D form});

...

})

</script>

Well, first look at the code simplification effect: Determine if test equals 1 end alert results

The code is as follows Copy Code

$ (' #test '). Dform ({

' Allerror ': false,

' Equal ': ' 1 ',

' Complete ': function (res) {

Alert (RES)

}

})

To determine if TEST contains an English letter (not a character) Error alert result

The code is as follows Copy Code

$ (' #test '). Dform ({

' Allerror ': false,

' Hasen ': true,

' Error ': function (res) {

Alert (RES)

}

})

To determine if test conforms to the regular expression if the alert result is met

The code is as follows Copy Code

$ (' #test '). Dform ({

' Allerror ': false,

' Preg ':/123/,

' Success ': function (res) {

Alert (RES)

}

})

Determines if test is a number and is greater than 1 if the correct alert result Allerror returns all result sets

If Isnum = False Res.isnum = False Res.min = True if Min = True

The code is as follows Copy Code

$ (' #test '). Dform ({

' Allerror ': true,

' Isnum ': true,

' min ': 1,

' Success ': function (res) {

Alert (RES)

}

})

Determine if test is not empty and must be a number if correct alert result

Allerror = False to return False if Noempty and Isnum are true res equals true

The code is as follows Copy Code

$ (' #test '). Dform ({

' Allerror ': false,

' Noempty ': true,

' Isnum ': true,

' Success ': function (res) {

Alert (RES)

}

})

Determine if test meets the requirements: match return alert true reverse false

Must not be empty (for numbers or for English letters) ======> (IsEn | | isnum) && noempty

The code is as follows Copy Code

var test1 = $ (' #test '). Dform ({

' Allerror ': false,

' Noempty ': true,

' Isnum ': true

})

var test2 = $ (' #test '). Dform ({

' Allerror ': false,

' Noempty ': true,

' IsEn ': true,

' Complete ': function (res) {

if (test1.getresponse () = = True | | res = = TRUE) alert (true)

else alert (false)

}

})

1233333333333333333333333333333

/*

* $ (' #pw ') for input password ID=PW according to J
Query to define

* $ (' #pw2) for input password id=pw2

function

* Mainly used to detect whether the password is the same as the password two

* Simultaneously detects whether the PW is null if NULL returns FALSE

**/

var DPW = $ (' #pw '). Dform ({

' Allerror ': false,

' Cache ': false,

' Noempty ': true,

' Equal ': $ (' #pw2 '),

' Complete ': function (res) {

$ (' #pwR '). Val (res);

}

})

var DPW = $ (' #pw2). Dform ({

' Allerror ': false,

' Cache ': false,

' Noempty ': true,

' Equal ': $ (' #pw '),

' Complete ': function (res) {

$ (' #pwR '). Val (res);

}

})

There is one to make clear that the class is temporarily used only for objects in form if editable Iframe/div is temporarily not available and should be the case for input radio:

The code is as follows Copy Code

/**

function

* Mainly used to determine whether the selection of male if selected then output male or female output;

*

* Equal must be equal to 1

*/

var dsex = $ (' input:radio[name= ' gender '] '). Dform ({

' Allerror ': false,

' Equal ': 1,

' Event ': ' Change ',

' Complete ': function (res) {

$ (' #sexR '). Val (res? ' Male ': ' Female ';

}

})

You can do this if you want to use a button to detect:

/**

function

* When clicking $ (' #btnR ') button id = Btnr

* Run detection;

* To determine if the number here is not a valid number 00.00 so correct

* Effective numbers with iseffectivenum properties or functions;

**/

var dbtn = $ (' #btn '). Dform ({

' Trigger ': $ (' #btnt '),

' Allerror ': false,

' Isnum ': true,

' Event ': ' Click ',

' Complete ': function (res) {

$ (' #btnR '). Val (Res)

}

})

Now it looks like it's better than no ... but this simple judgment will definitely be able to see the role of this plug-in to a little bit more complex:

The code is as follows Copy Code

/**

* Function: To load the date of the current two years into

* $ (' #year ') years Select id = year

* $ (' #month ') year SELECT id = month

* $ (' #date ') year SELECT id = Date

* At the same time to determine how many days of the month, such as non-leap year February only 28th

*

* Ready is a method of running after loading if this method is used directly for the distribution of the object;

* The Extend method is that the extension method class must be added in the form of class function () {}

* The method in which the class is invoked can use this directly;

* Event defaults to blur can change its trigger action;

* Complete is the code that ends up being run;

*

* This method is mainly not applied in the validation and the selection of synchronous mutation

**/

var dyear = $ (' #year '). Dform ({

' Ready ': function () {

This.resetyear ();

},

' Extend ': function () {

This.resetyear = function () {

This.cleanoptions ();

var now = new Date ();


n class= "keyword" >for (var i = now.getfullyear (); I < Now.getfullyear () + 2; i + +) this.addoptions (i);

}

},

' Event ': ' Change ',

' Complete ': function () {

Dmonth.resetmonth ();

Ddate.resetdate ();

}

})

var dmonth = $ (' #month '). Dform ({

' Ready ': function () {

This.resetmonth ();

},

' Extend ': function () {

This.resetmonth = function () {

var month = This.val ();

This.cleanoptions ();

for (var i = 1; i < i + +) this.addoptions (i, I < 10?) ' 0 ' + i:i);

This.val (month);

}

},

' Event ': ' Change ',

' Complete ': function () {

Ddate.resetdate ();

}

})

var ddate = $ (' #date '). Dform ({

' Ready ': function () {

This.resetdate ();

},

' Extend ': function () {

This.resetdate = function () {

var date = This.val ();

This.cleanoptions ();

var maxdate = new Dform (). Getdaysinmonth (parseint (Dyear.val ()), parseint (Dmonth.val ()));

for (var i = 1; i < maxdate + 1; i + +) this.addoptions (i, I < 10?) ' 0 ' + i:i);

This.val (date);

}

}

})

These three are interrelated 3-level associations I do is year-by-day five-level association and cannot exceed the current time. This three-level association is easier to understand. What if I'm going to use Ajax to do it without having to use Jquery.ajax ({}) to commit and process it? This also takes into account the use of Ajax in the inside and is exactly the same as the $.ajax ({}) method in jquery

/**

function

* Mainly verify is not the email address;

* Simultaneously request the server to see whether the mailbox address is occupied

*

* $ (' #email ') input text id = Email

* Method Detection methods are custom methods that can be added with extend (function () {})

* or the Dformet method of JS file added

* Run before before operation

* Wait waiting for run in the main for Ajax when running

* Error errors are run

* Success Run correctly

* Complete at the end of the run, whether right or wrong;

*/

var demail = $ (' #email '). Dform ({

' Allerror ': false,

' method ': ' Isemail ',

' Ajax ': {

' type ': ' Post ',

' DataType ': ' JSON ',

' URL ': ' ajax.php '

},

' Before ': function () {

$ (' #emailR '). Val (' Beforefunc ');

},

' Wait ': function () {

$ (' #emailR '). Val (' Waitfunc ');

},

' Error ': function (res) {

$ (' #emailR '). Val (' ERROR: ' + res);

}, &
nbsp

' Success ': function (res) {

$ (' #emailR '). Val (' success: ' + res);

},

' Complete ': function (res) {

$ (' #emailR '). Val (' Complete: ' + res);

}

});

In addition, the method can be used to manipulate the numerical value directly.

Dform (). Empty (")//" whether or not ";

Dform (). Noempty (")//" is not ";

Dform (). Equal (' 123 ', ' 321 ')//' 123′ is ' 123′

Dform (). Equal ($ (' #pw '), $ (' #pw2])//$ (' #pw ') is equal to $ (' #pw2 ')

Dform (). Noequal ($ (' #pw '), $ (' #pw2) ')//$ (' #pw ') is not equal to $ (' #pw2 ')

Dform (). Noequal (' 123 ', ' 321 ')//321 is not equal to 123

Dform () min (122, 321)//321 is not less than 123 (this is the number of the judge string also line)

Dform () Max (122, 321)//321 is not greater than 123 (IBID.)

Dform (). Length (3, ' 123 ', ' > ')//' 123′ characters are > 3

Dform (). Length (13, ' Test first Q ', ' >= ', ' All ', ' utf8′,/[^u4e00-ufa29]/g,/[u4e00-ufa29]/g ')

Dform (). Preg (/[u4e00-ufa29]/g, ' excuse me ')//Regular

Dform (). Minchlength (3, ' ask ') whether the character length is not less than 3

Dform (). Maxchlength (3, ' ask ') whether the character length is not greater than 3

Dform (). Minenlength (3, ' qweq ')//English character length is not less than 3

Dform (). Maxenlength (3, ' qweq ')//English string degree is not greater than 3

Dform (). MinLength (10, ' Weapon Q ')//character length is not less than 10

Dform (). MinLength (9, ' weapons Q ', ' All ', ' utf8′,/[^u4e00-ufa29]/g,/[u4e00-ufa29]/g ')

Dform (). MaxLength (9, ' weapons Q ', ' All ', ' utf8′,/[^u4e00-ufa29]/g,/[u4e00-ufa29]/g ')

Dform (). Minchorenlength (4, 7, ' ask Qwe ')//character length is not greater than 10

Dform (). Minchorenlength (3, 6, ' Ask Qwe ', ' utf8′,/[^u4e00-ufa29]/g,/[u4e00-ufa29]/g)

Dform (). Maxchorenlength (3, 6, ' Ask Qwe ', ' utf8′,/[^u4e00-ufa29]/g,/[u4e00-ufa29]/g)

Dform (). Hasen (' Ask Wqe ') whether it contains English letters excluding punctuation figures

Dform () Hasch (' Ask Wqe ') whether it contains Chinese punctuation, including Chinese

Dform (). Nohasen (' qwe ')/whether does not contain

Dform (). Nohasch (' qwe ')/whether does not contain

Dform () Hasennoch (' qwe ')/Whether only Chinese is not English

Dform (). Haschnoen (' qwe ')/whether only English is not Chinese

Dform () Haschanden (' ask ') whether there is Chinese and Chinese

Dform (). Isemail (' qowera@qq.com ')/Whether it is a mailbox

Dform (). Isemail (' qowera@qq.com ', true)/whether the mailbox will verify the error results of the mailbox all output;

Dform (). ISPASSW
Ord (' 123qwe7890!@#$%67 ')/whether is the password can fill true ditto

Dform (). Isname (' ox ')/Whether the name is customized specifically for must only Chinese or English can not be less than 2 Chinese characters can not be more than 10 characters in English can not be less than 2 English characters can not be more than 10 English characters

Dform (). Isname (' 123 ', true)//on the same

Dform (). Touppermoney (' en ', ' 11231223.132 ')//money converted to thousands separated by commas

Dform (). Touppermoney (' ch ', ' 11231223.132 ')//money into Chinese form;

Whether the Dform (). Iseffectivenum (' 23 ')//is a valid number;

Publish all of the attributes a little bit to change a bit better not to change;

var options = {

' Trigger ': null,//trigger;

' target ': null,//object;

' Allerror ': true,//return all results all/single;

' Cache ': true,//cache;

' Language ': ' en ',//EN, ch;

' CharSet ': ' utf8′,//UTF8, GBK;

' tag ': ' Input ',//target's tag;

' Type ': ' Text ',//target type;

' response ': {},//set resonse initial value;

' value ': null,//Set initial value;

' typeset ': New Array (' > ', ' < ', ' >= ', ' <= ', ' = = '),

' CharSet ': New Array (' utf8′, ' GBK '),

' Languageset ': New Array (' en ', ' ch ', ' all '),

' Pregset ': {

' Enchar ':/[^u4e00-ufa29]/,

' Chchar ':/[u4e00-ufa29]/,

' En ':/^[a-za-z]+$/,

' ch ':/^[u4e00-ufa29]+$/,

' num ':/[0-9]+/,

' Effectivenum ':/^ ([1-9][0-9]* (.)? [0-9]+|0 (.) [0-9]+| [1-9] [0-9]*[0-9]*) $/

},

' Upper ': {

' num ': New Array (' 0 ', ' one ', ' II ', ' three ', ' Restaurant ', ' Wu ', ' land ', ' qi ', ' ba ', ' nine '),

' unitadvanced ': New Array (' Circle ', ' million ', ' billion ', ' trillion ', ' Jing ', ' Gai ', ' 秭 ', ' rang ', ' ditch ', ' brook ', ' right ', ' load ', ' pole ', ' Ganges ', ' Monk? ', ' that by him ', ' inconceivable ', ' Immeasurable ', ' large number '),

' Unitlow ': New Array (' Thousand ', ' Bai ', ' pick ', '),

' Unitdecimal ': New Array (' Angle ', ' min ', ', ')

},

' Line ': New Array (//Operation sequential;

' Method ', ' selected ', ' Empty ', ' noempty ', ' equal ', ' noequal ',

' min ', ' Max ', ' between ', ' Minlen ', ' maxlen ', ' minenorchlength ',

' Maxenorchle
Ngth ', ' minenlength ', ' maxenlength ', ' minchlength ', ' maxchlength ',

' IsEn ', ' Isch ', ' isnum ', ' iseffectivenum ', ' Isenchar ', ' Nohasenchar ', ' nohasnum ',

' Nohasenchar ', ' Nohaschchar ', ' Hasenchar ', ' Haschchar ', ' hasnum ',

' Preg ', ' Ajax '

),

' Package ': New Array (),//encapsulation of good methods;

' method ': null,//detection methods;

' selected ': null,//choice;

' Empty ': null,//Must be empty;

' Noempty ': null,//cannot be empty;

' equal ': null,//must equal;

' noequal ': null,//cannot equal;

' min ': null,//must be greater than or equal to (number);

' Max ': null,//must be less than or equal to (number);

' Between ': null,//must be greater than or equal to and less than equal;

' Minlen ': null,//character length must be greater than or equal;

' MaxLen ': null,//character length must be less than or equal;

' minenorchlength ': null,//English must be greater than or equal to or Chinese must be greater than or equal to;

' maxenorchlength ': null,//English must be less than or equal to or Chinese must be less than equal;

' minenlength ': null,//English must be greater than or equal to;

' maxenlength ': null,//English must be less than or equal;

' minchlength ': null,//Chinese must be greater than or equal to;

' maxchlength ': null,//Chinese must be less than equal;

' isEn ': null,//Must be English;

' Isch ': null,//Must be Chinese;

' Isnum ': null,//must be a number;

' Iseffectivenum ': null,//must be a valid number;

' Isenchar ': null,//must be English character;

' Ischchar ': null,//Must be Chinese character;

' Nohasenchar ': null,//must not contain English characters;

' Nohaschchar ': null,//must not contain Chinese characters;

' Nohasnum ': null,
Must not contain a number (string);

' Hasenchar ': null,//must contain English characters;

' Haschchar ': null,//must contain Chinese characters;

' Hasnum ': null,//must contain a number (string);

' Preg ': null,//testing is in compliance;

' Ajax ': null,//trigger AJAX request;

' Ready ': null,//initialized to run after Func;

' Extend ': null,//extension method class;

' Event ': ' Blur ',//triggers the elements of the event;

' Before ': function () {},//Pre func triggered

' Wait ': function () {},//Waiting func is mainly used for Ajax wait;

' Error ': function () {},//Trigger error Func

' Success ': function () {},//Trigger success Func

' Complete ': function () {}//Trigger complete Func

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.