CaCheckerV0.1.2 Beta2 released

Source: Internet
Author: User
Tags control label rtrim

Cacheckerv0.1.2 beta2

CaChecker is a free and easy-to-use JavaScript form verification framework that is coupled with HTML Tag 0. caChecker supports custom verification functions to expand the verification function. To verify a large form containing 100 elements, it only takes about 10 minutes to configure the rules, without the need to copy and paste a large amount of code. CaChecker perfectly separates form and verification. To use caChecker, you do not need to add any attributes or methods to the original form or html control label. You only need to import a JS file, the system automatically adapts to the FORM defined by the rule. You do not need to worry that the onsubmit on the original Form tag cannot run normally, and the onload on the body Tag is invalid. CaChecker uses the principle of proxy to ensure the perfect execution of the original event. Currently, caChecker supports Firefox, IE, Opera, and other browsers. Now let's explore the secrets of caChecker!

Latest download:

CaCheckerV0.1.2 Beta2


Version update description:

Cacheckerv0.1.2

Release date:

1. Failed to fix custom onsubmit event submission control.

2. Added url, mobile, number, and color verification.

3. Add a namespace to the framework.

Cacheckerv0.1.1

Release date:

Complete the core code and support email, length, and empty verification.

Procedure:

1. Import the framework JS,Cachecker. js

2. Write the verification rule CACHK. addCheckForm (form name [-N], rule );

Detailed description:

CACHK. addCheckForm (form name [-N], rule );

Add a rule for each form.

Form name [-N]: multiple form name attributes on the same page are the same. You can add-N, for example:

Form1:
<Form name = "myForm"> content 1 </form>

Form2:
<Form name = "myform"> content 2 </form>

Cachk. addcheckform (myForm-0, rule 1 );
Cachk. addcheckform (myForm-1, rule 2 );

The index starts from 0!

 

Rule Description:

VaR role = ["0 | empty | 0 | sex name", "1 | Len |> 6 | age", "2 | email | 0 | email"];

Verification rules can be defined as variables for reuse.

Custom verification: cachk. Chk _ FUNCTION suffix

Chk _: Required! Is the framework convention!

For example, student Form Verification:
Cachk. chk_studentform = function (ELEM, role ){
If (ELEM. value = ""){
This. showerrors (ELEM, role, "cannot be blank! ");
Return false;
}
Return true;
};

Parameter description:

ELEM: element reference to be verified!

Role:
Role. elemindex element index
Role. roletype rule type (empty, Len, mail, URL, etc.), verify function suffix
Role. roleIf rule condition (depending on the rule function). This value can be obtained for processing when you define a rule function.
Role. elemName: The name (name, age, gender, etc.) of the element. caChecker will generate a prompt statement based on the element name.

Integrated verification Library:

Verification library suffix Verification library description Verification Conditions
Len Length limit > N, <n ,! = N, = N, etc.
URL URL? No verification Conditions Required
Mail Email? No verification Conditions Required
Mobile Mobile phone number? It can start with 13 and start with the last 9 digits! (No verification conditions required)
Empty Empty or not 0 indicates that the value cannot be blank. 1 indicates that the value must be blank.
Number Number type? No verification Conditions Required
Color Color type (# ff0087) No verification Conditions Required

Common function libraries:

Function Name Function Description Instructions for use
Showerrors (ELEM, role, Info) Display prompt information Verification function:
This. showerrors (ELEM, role, Info );
Cachk. showerrors (ELEM, role, Info );
External execution:
Cachk. showerrors (ELEM, role, Info );
Isnull (string) Whether it is null or undefined Verification function:
This. isnull (string );
Cachk. isnull (string );
External execution:
Cachk. isnull (string)
Getelementbyevent (Event)
 
Obtain the trigger element from the event object Verification function:
This. getelementbyevent (event );
Cachk. getelementbyevent (event );
External execution:
Cachk. getelementbyevent (event );
Ltrim (string) Left space

Verification function:
This. ltrim (string );
CACHK. ltrim (string );
External execution:
CACHK. ltrim (string );

Rtrim (string) Right Space Verification function:
This. rtrim (string );
CACHK. rtrim (string );
External execution:
CACHK. rtrim (string );
Trim (string) Left and right Spaces Verification function:
This. trim (string)
CACHK. trim (string)
External execution:
CACHK. trim (string)

We recommend that you use the CACHK. XXXX method to call all of them!

Complete example:

Example.html
<Html>
<Head>
<Title> caCheckerV1.0 Beta1 Example </title>
<Script type = "text/javascript" src = "caChecker. js">
</Script>
<Script type = "text/javascript">
Var formRole1 = ["0 | empty | 0 | Name", "1 | len |> 6 | password"];
Var formRole2 = ["0 | mail | 0 | email", "1 | empty | 0 | address", "1 | address | Shanghai | address"];
CACHK. addCheckForm ("studentForm-0", formRole1 );
CACHK. addCheckForm ("studentForm-1", formRole2 );

// Custom verification function
CACHK. chk_address = function (elem, role ){
Var v = this. trim (elem. value );
If (v. indexOf (role. roleIf) =-1 ){
CACHK. showErrors (elem, role, "only allowed" + role. roleIf );
Return false;
}
Return true;
};

// Form onsubmit event
Function reCheckForm (formObj, formName ){
Alert (formName + "passed verification! But I won't pass it here! ");
Return false;
}
</Script>
</Head>
<Body>
<Form name = "studentForm" onsubmit = "return reCheckForm (this, 'studentform1 ');">
Name: <input type = "text" name = "userName"/> <br/>
Password: <input type = "password" name = "userPwd"/> <br/>
<Input type = "submit" value = "save"/>
<Input type = "reset" value = "reset"/>
</Form>
<Form name = "studentForm" id = "vaaaa">
Email: <input type = "text" name = "userName"/> <br/>
Address: <input type = "text" name = "userPwd"/> <br/>
<Input type = "submit" value = "save"/>
<Input type = "reset" value = "reset"/>
</Form>
</Body>
</Html>
 
 

View examples

 

Download verification framework:

Cachecker. js

Mr. CT
Ant software Studio
2009-06-

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.