. The JS verification of forms in net

Source: Internet
Author: User

JS Verification code is as follows: (need to introduce two JS packets)

1     <Scripttype= "Text/javascript"src= "/js/jquery.validate.min.js"></Script>2     <Scripttype= "Text/javascript"src= "/js/jquery-1.7.2.js"></Script>3      <Scripttype= "Text/javascript">4         functionValidatecartoon () {5             varname= $("#txtCompany"). Val (). Trim ();6             if(Name==""){7 Alert ("Company/organization name cannot be empty! ");8                 return false;9             }Ten             varMobile= $("#txtName"). Val (). Trim (); One             if(Mobile==""){ A Alert ("the name cannot be empty! "); -                 return false; -             } the            varEmail=$("#txtEmail"). Val (). Trim (); -            varpattern= /^ ([\.a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + (\.[ a-za-z0-9_-]) +/; -            if(Email==""){ - Alert ("The mailbox cannot be empty"); +             return false; -            } +            if (!pattern.test (email)) {   A Alert ("Please enter the correct email address. ");  at                 return false;  -             }   -             varMobile= $("#txtPhone"). Val (). Trim (); -             varStr=/^ ((1[3|5|7|8][0-9]{1}) +\d{8}) $/; -             if(Mobile==""){ - Alert ("the contact number cannot be empty! "); in             return false; -             } to             Else if(!Mobile.match (str)) { + Alert ("Please enter the correct 11-digit phone number! "); -             return false; the             } *  $            return true;Panax Notoginseng              -         } the     </Script>
View Code

. NET code is as follows:

1<form id="Form1"runat="Server">2<div>3<div> contact information is as follows:</div>4<dl>5<dt> <spanclass='cRed'>*</span> Company/unit name (required) </dt>6<dd><asp:textbox id="Txtcompany"runat="Server"></asp:TextBox></dd>7</dl>8<dl>9<dt><spanclass='cRed'>*</span> name (required) </dt>Ten<dd><asp:textbox id="txtname"runat="Server"></asp:TextBox></dd> One</dl> A<dl> -<dt><spanclass='cRed'>*</span> Email address (required, check email format) </dt> -<dd><asp:textbox id="Txtemail"runat="Server"></asp:TextBox></dd> the</dl> -<dl> -<dt> Phone (optional) </dt> -<dd><asp:textbox id="Txtphone"runat="Server"></asp:TextBox></dd> +</dl> -<asp:button id="btnsubmit"runat="Server"text="Submit Information"onclientclick="return Validatecartoon ()"onclick="btnSubmit_Click"/> +</div> A</form>
View Code

This can be done as shown in the code above. NET form of JS validation.

. The JS verification of forms in net

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.