Common javascript code for user registration

Source: Internet
Author: User
Tags valid email address

Copy codeThe Code is as follows:
<% @ Page contentType = "text/html; charset = gb2312" language = "java" %>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> User Registration </title>
<Script language = "javascript">
Function IsDigit (cCheck)
{
Return ('0' <= cCheck) & (cCheck <= '9 '));
}

Function IsAlpha (cCheck)
{
Return ('A' <= cCheck) & (cCheck <= 'Z') | ('A' <= cCheck) & (cCheck <= 'Z ')))
}

Function IsValid ()
{
Var struserName = reg. UserName. value;
For (nIndex = 0; nIndex <struserName. length; nIndex ++)
{
CCheck = struserName. charAt (nIndex );
If (! (IsDigit (cCheck) | IsAlpha (cCheck )))
{
Return false;
}
}
Return true;
}
Function chkEmail (str)
{
Return str. search (/[\ w \-] {1,} @ [\ w \-] {1 ,}\. [\ w \-] {1,}/) = 0? True: false
}

Function docheck ()
{
If (reg. UserName. value = "")
{
Alert ("Enter the user name ");
Return false;
}
Else if (! IsValid ())
{
Alert ("the user name can only contain letters and numbers ");
Return false;
}
Else if (reg. UserPassword. value = "")
{
Alert ("enter the password ");
Return false;
}
Else if (reg. UserPassword. value! = Reg. CUserPassword. value)
{
Alert ("inconsistent passwords ");
Return false;
}
Else if (reg. NickName. value = "")
{
Alert ("Enter your nickname ");
Return false;
}
Else if (reg. Email. value = "")
{
Alert ("Enter your email address ");
Return false;
}
Else if (! ChkEmail (reg. Email. value ))
{
Alert ("Please enter a valid Email Address ");
Return false;
}
Else
{
Return true;
}
}
</Script>
<STYLE type = text/css>
Td, th {
Font-family: Arial, Helvetica, sans-serif;
Font-size: 14px;
Line-height: 24px;
Color: #333333;
}
</STYLE>
</Head>
<Body>
<H1 align = "center"> User Registration <Div align = "center">
<Form name = "reg" action = "user_add.jsp" method = "post" target = "_ self" onSubmit = "return docheck ()">
<Table width = "90%" border = "0">
<Tr>
<Td width = "50%" align = "right" height = "25"> <font face = "Arial, Helvetica, sans-serif"> enter the user name to register: </font> </td>
& Lt; td width = "50%" align = "left" height = "25" & gt;
<Input type = "text" name = "UserName">
<Br>
<Font color = "red"> a user name can only consist of letters and numbers </font>
</Td>
</Tr>
<Tr>
<Td width = "50%" align = "right" height = "25"> enter the password: </td>
<Td width = "50%" align = "left" height = "25"> <input type = "password" name = "UserPassword"> </td>
</Tr>
<Tr>
<Td width = "50%" align = "right" height = "25"> enter the password: </td>
<Td width = "50%" align = "left" height = "25"> <input type = "password" name = "CUserPassword"> </td>
</Tr>
<Tr>
<Td width = "50%" align = "right" height = "25"> enter the nickname: </td>
<Td width = "50%" align = "left" height = "25"> <input type = "text" name = "NickName"> </td>
</Tr>
<Tr>
<Td width = "50%" align = "right" height = "25"> select gender: </td>
<Td width = "50%" align = "left" height = "25"> <input type = "radio" name = "Sex" value = "0" checked> male <input type = "radio" name = "Sex" value = "1"> female </td>
</Tr>
<Tr>
<Td width = "50%" align = "right" height = "25"> enter the Email address: </td>
<Td width = "50%" align = "left" height = "25"> <input type = "text" name = "Email"> </td>
</Tr>
</Table>
<P>
<Input type = "submit" name = "sub" value = "register">
<Input type = "reset" name = "res" value = "Refill">
</P>
</Form>
</Div>
</Body>
</Html>

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.