JQuery front-end Comment Form Verification instance Summary

Source: Internet
Author: User
Tags wordpress blog

The following is a jquery Form Verification example that I will share with you through the wordpress blog front-end Comment Form Verification. I hope this tutorial will be helpful to you.

WordPress also has form verification, but we all know that the user experience is not good at all, page Jump occurs, sometimes the form is cleared, and the front-end form authentication is very necessary. The following code prompts the user to enter the content by changing the background color of the text box. WordPress only needs to put the following code in the js file to work. The verification is triggered by clicking the submit button. For how it works, see the comments.

The Code is as follows: Copy code

// Form Verification
$ (Function (){
$ ('# Submit'). click (function (){
Var $ author = $ ('# author'). val (); // name
Var $ email = $ ('# email'). val (); // email
Var $ url = $ ('# url'). val (); // url
Var $ textarea = $ ('textarea: first'). val (); // comment
Var $ errorNo = 0;
If ($ author = ""){
Certificate ('author').css ("background", "# F9A4A4 ");
$ ErrorNo + = 1;
} Else {
Certificate ('{author'}.css ("background", "# FFF ");
}
If ($ email = ""){
Certificate ('{email'}.css ("background", "# F9A4A4 ");
$ ErrorNo + = 1;
} Else if (! /^ (? : [A-zd] + [_-+.]?) * [A-zd] + @(? :( [A-zd] + -?) * [A-zd] +.) + ([a-z] {2,}) + $/I. test ($ email )){
Certificate ('{email'}.css ("background", "# F9A4A4 ");
$ ErrorNo + = 1;
} Else {
Certificate ('{email'}.css ("background", "# FFF ");
}
If ($ url! = ""&&! /^ Http: // [A-Za-z0-9] +. [A-Za-z0-9] + [/=? % -&_~ '@ []': +!] * ([^ <> ""]) * $/. Test ($ url )){
Certificate ('{url'}.css ("background", "# F9A4A4 ");
$ ErrorNo + = 1;
} Else {
Certificate ('{url'}.css ("background", "# FFF ");
}
If ($ textarea = ""){
$ ('Textarea: first'hangzhou.css ("background", "# F9A4A4 ");
$ ErrorNo + = 1;
} Else {
$ ('Textarea: first'hangzhou.css ("background", "# FFF ");
}
If ($ errorNo> 0 ){
Return false;
}
});
});

This is a very simple form verification ~ This is what Xiao Bo is doing now. please correct me for improvement ~

Example 2

Determine whether the drop-down box has a choice:

The Code is as follows: Copy code

<Script type = "text/JavaScript">

Function CheckForm (){

Var AreaValue = $ ("# DDlAreaList"). val ();

If (AreaValue = "0 ")

{

Top. Dialog. altert ("select a region! ");

Return false;

}

Return true;

}

</Scirpt>

<Asp: Button ID = "btnSubmit" runat = "server" Text = "Save and return" Width = "80px" CssClass = "blueButtonCss" OnClientClick = "return CheckFrom (); "OnClick =" btnSubmit_Click "/> & nbsp;

Use of SQL statements in IBatisNet:

The Code is as follows: Copy code

<! -- <Select id = "searchDeclaration" resultMap = "T_ED_DeclarationResult" parameterClass = "T_ED_Declaration">
Select a. * FROM [T_ED_Declaration]
<Dynamic prepend = "WHERE">
<IsNotEmpty prepend = "and" property = "Declaration_BatchNO">
A. Declaration_BatchNO like '% $ Declaration_BatchNO $ %'
</IsNotEmpty>
<IsNotEqual prepend = "and" property = "Declaration_PortName" comparevalue = "0">
A. Declaration_PortName like '% $ Declaration_PortName $ %'
</IsNotEqual>
<IsGreaterThan prepend = "and" property = "StartTime" compareValue = "1900-1-1">
<! [CDATA [
A. StartTime <= # StartTime #
]>
</IsGreaterThan>
<IsGreaterThan prepend = "and" property = "EndTime" compareValue = "1900-1-1">
<! [CDATA [
A. EndTime <= # EndTime #
]>
</IsGreaterThan>
</Dynamic>
</Select> -->

Related Article

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.