JQuery foreground comment Form Validation instance summary

Source: Internet
Author: User
Tags cdata

WordPress, of course, there are forms of verification, but we all know that the user experience is not good, the page jumps, and sometimes the form will be emptied, and the front desk form certification seems very necessary. The following is my written by changing the text box background color prompts the user input content, WordPress as long as the following code into the JS file can work. The validation is triggered by clicking on the Submit button and working to see the annotation.

The code is as follows

//Form Verification


$ (function () {


$ (' #submit '). Click (function () {


var $author =$ (' #author '). Val (); Name


var $email =$ (' #email '). Val (); Mailbox


var $url =$ (' #url '). Val (); Web site


var $textarea =$ (' Textarea:first '). Val (); Comment


var $errorNo = 0;


if ($author = = "") {


$ (' #author '). CSS ("Background", "#F9A4A4");


$errorNo +=1;


}else{


$ (' #author '). CSS ("Background", "#FFF");


        }


if ($email = = "") {


$ (' #email '). CSS ("Background", "#F9A4A4");


$errorNo +=1;


}else if (!/^ (?: [a-zd]+[_-+.]?) *[a-zd]+@ (?:( [a-zd]+-?] *[a-zd]+.) + ([A-z]{2,}) +$/i.test ($email)) {


$ (' #email '). CSS ("Background", "#F9A4A4");


$errorNo +=1;


}else{


$ (' #email '). CSS ("Background", "#FFF");


        }


if ($url!= "" &&!/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> ""]) *$/.test ($url)) {


$ (' #url '). CSS ("Background", "#F9A4A4");


$errorNo +=1;


}else{


$ (' #url '). CSS ("Background", "#FFF");


        }


if ($textarea = = "") {


$ (' Textarea:first '). CSS ("Background", "#F9A4A4");


$errorNo +=1;


}else{


$ (' Textarea:first '). CSS ("Background", "#FFF");


        }


if ($errorNo >0) {


return false;


        }


});


});

Such a very simple verification of the form came out ~ The effect is Xiao Bo now, welcome to improve ~

Example 2

Determine if the dropdown box has a selection:

The code is as follows

<script type= "Text/javascript" >

function Checkform () {

var areavalue=$ ("#DDlAreaList"). Val ();

if (areavalue== "0")

{

Top. Dialog.altert ("Please select area!") ");

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;&nbsp;

About the use of SQL statements in Ibatisnet:

The code is as follows

<!--<select id= "Searchdeclaration" resultmap= Declarationresult "parameterclass=" "T_ed_declaration"
      SELECT a.* from [t_ed_ Declaration] A
      <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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.