Simple Example of Asp.net JavaScript Form Verification

Source: Internet
Author: User

 

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
<Script language = JavaScript>
Function check ()
...{
/** // Note the Regular Expression in javascript:/representation/
VaR Rg =/^ [w-] + (. [w-] +) * @ [w-] + (. [w-] +) + $ /;

If (document. getelementbyid ("txtid"). value = "000 ")
...{

Alert ("can't be 000 ");
Document. All ("txtid"). Focus ();
Return false;
}
 
VaR STR = Document. getelementbyid ("txtmail"). value;
If (! RG. Test (STR ))
...{
Alert ("email addess Error !! ");
Document. All ("txtmail"). Focus ();
Return false;
}
Else
...{
Return true;
}


}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Asp: textbox id = "txtmail" runat = "server" style = "Left: 270px; position: relative;
Top: 221px "> </ASP: textbox>;
<! -- Notes: "onclientclick" and "onclick" the use of the 'return '-->
<Asp: button id = "btulogin" onclientclick = "Return check ()" runat = "server" style = "Left: 211px; position: relative; top: 289px"
TEXT = "button" onclick = "btulogin_click"/>
<Asp: textbox id = "txtid" runat = "server" style = "Left: 48px; position: relative;
Top: 159px "> </ASP: textbox> & nbsp;
</Form>
</Body>
</Html>

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.