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 Copy Code

Form validation
$ (function () {
$ (' #submit '). Click (function () {
var $author =$ (' #author '). Val (); Name
var $email =$ (' #email '). Val (); Mailbox
var $url =$ (' #url '). Val (); Url
var $textarea =$ (' Textarea:first '). Val (); Comments
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 Copy Code

<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 Copy Code

<!--<select id= "searchdeclaration" resultmap= "T_ed_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>-->

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.