Simple example of jquery Ajax form verification

Source: Internet
Author: User

Example!

The code is as follows: Copy code

 

<Div class = "bdbox">
<Ul>
<Li> <span class = "bdl"> <em> * </em> Company name: </span> & nbsp; <span class = "bdr"> <input id = "companynames" name = "companyname" size = "30" class = "txt"/> </span> </li>
<Li> <span class = "bdl"> <em> * </em> Enterprise website: </span> & nbsp; <span class = "bdr"> <input id = "companyurls" name = "companyurl" size = "30" class = "txt"/> </span> </li>
<Li> <span class = "bdl"> <em> * </em> Your Title: </span> & nbsp; <span class = "bdr"> <input id = "names" name = "name" size = "30" class = "txt"/> </span> </li>
<Li> <span class = "bdl"> <em> * </em> your mobile phone: </span> & nbsp; <span class = "bdr"> <input id = "phones" name = "phone" size = "30" class = "txt"/> </span> </li>
<Li class = "gaob"> <span class = "bdl"> & nbsp; remarks: </span> <span class = "bdr"> <textarea id = "notes" name = "note" rows = "3" cols = "26" onfocus = "if (value = 'enter other content you want to talk about! ') {Value = ''}" onblur = "if (value ='') {value =' fill in other content you want to talk about! '} "> Enter other content you want to talk about! </Textarea> </span> </li>
<Li class = "gaoc">
<Input id = "wfsubmits" type = "image" src = "_ PUBLIC _/images/lijishenqing.jpg"
Onclick = "customerAdds ()" name = "wfsubmits" value = "" class = "send"/>
<Input type = "hidden" value = "" name = "web_ref" id = "web_ref"/>
</Li>
</Ul>
</Div>
<Script type = "text/javascript">
Function customerAdds (){
$ ("# Wfsubmits"). attr ('disabled ', 'disabled ');
Var companyname = $ ("# companynames"). val ();
Var companyurl = $ ("# companyurls"). val ();
Var name = $ ("# names"). val ();
Var phone = $ ("# phones"). val ();
Var note = $ ("# notes"). val ();
 
If (companyname = ''){
Ui. error ("enterprise name cannot be blank! ");
$ ("# Wfsubmits"). removeAttr ('disabled ');
Return false;
   }
If (name = ''){
Ui. error ("Your name cannot be blank! ");
$ ("# Wfsubmits"). removeAttr ('disabled ');
Return false;
   }
If (phone = ''){
Ui. error ("The mobile phone number cannot be blank! ");
$ ("# Wfsubmits"). removeAttr ('disabled ');
Return false;
} Else if (isPhone (phone) = false ){
Ui. error ("incorrect mobile phone number format! ");
$ ("# Wfsubmits"). removeAttr ('disabled ');
Return false;
  }
$. Post ("{: U ('Home/Index/ajaxaddcustomer')}", {companyname: companyname, companyurl: companyurl, name: name, phone: phone, note: note }, function (res ){
If (res> 0 ){
$ ("# Companynames"). val ('');
$ ("# Companyurls"). val ('');
$ ("# Names"). val ('');
$ ("# Phones"). val ('');
$ ("# Notes"). val ('');
Ui. success ('submitted successfully ');
} Else {
Ui. error ('submission failed ');
  }
$ ("# Wfsubmits"). removeAttr ('disabled ');
});
}
Function isPhone (str ){
Var re =/^ (\ d {3} \) | (\ d {3 }\-))? 13 [0-9] \ d {8 }? $ | 15 [0-9] \ d {8 }? $ | 18 [0-9] \ d {8 }? $ /;
If (re. test (str )! = True ){
Return false;
} Else {
Return true;
 } 
  }
</Script>

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.