Copy codeThe Code is as follows:
// JS Code
Function checkname (){
Var Msg = document. getElementById ("d_username ");
Var chk = CheckN ();
If (chk ){
$. Ajax ({url: 'registerok. aspx ',
Type: 'post ',
Data: {lb: "checkname", username: $ ("# username"). val ()},
DataType: 'html ',
Timeout: 1000,
Error: function () {alert ('unknown error, please contact QQ: 6434789. ');},
Success: function (data ){
If (data = "sorry, this user name has been registered! "){
Msg. className = "d_err ";
Msg. innerHTML = data;
$ ("# Hiddencheckname"). val ("no ");
}
If (data = "congratulations, this user name can be registered! "){
Msg. className = "d_ OK ";
Msg. innerHTML = data;
$ ("# Hiddencheckname"). val ("yes ");
}
If (data = "this user name cannot be Chinese! "){
Msg. className = "d_err ";
Msg. innerHTML = data;
$ ("# Hiddencheckname"). val ("no ");
}
If (data = "Enter the user name! "){
Msg. className = "d_err ";
Msg. innerHTML = data;
$ ("# Hiddencheckname"). val ("no ");
}
}
});
}
}
Function CheckN (){
Var Msg = document. getElementById ("d_username ");
Var chk = true;
If (checkIsChinese (document. getElementById ("username"). value )){
Msg. className = "d_err ";
Msg. innerHTML = "the user name cannot be Chinese! ";
Chk = false;
}
If (document. getElementById ("username"). value. length <4 ){
Msg. className = "d_err ";
Msg. innerHTML = "the user name cannot be less than 4 characters! ";
Chk = false;
}
Return chk;
}
Function chk_reguser (){
Var chk = true
// If (! Checkname () {chk = false;} // variables assigned by jquery cannot be shared with the variables in js, so success: function (data) the variables defined in {} are not the same as those in the js code, so I am looking for a relatively (informal) method, add hidden Input to html and set $ ("# hiddencheckname") in js "). val ("no ");
If (! CheckN () {chk = false ;}
If ($ ("# hiddencheckname"). val () = "no") {chk = false;} // This is to determine its
If (! Checkpwd () {chk = false;} // similar to CheckN (), the elements in the form are verified.
If (! Checkpwd1 () {chk = false ;}
If (! Checkquestion () {chk = false ;}
If (! Checkanswer () {chk = false ;}
If (! Checkxq () {chk = false ;}
If (! Checkrealname () {chk = false ;}
If (! Checktel () {chk = false ;}
If (! CheckQQMSN () {chk = false ;}
If (! CheckEmail () {chk = false ;}
If (! Checkaddress () {chk = false ;}
If (chk ){
$. Ajax ({url: 'registerok. aspx ',
Type: 'post ',
Data: {lb: "reguser", username: $ ("# username "). val (), password: $ ("# pwd "). val (), question: $ ("# question "). val (), answer: $ ("# answer "). val (), xqcode: $ ("# ctl00_CPH_Main_DDL_xq "). val (), realname: $ ("# realname "). val (), sex: $ ("input [@ name = sex] [@ checked]"). val (), tel: $ ("# tel "). val (), QQMSN: $ ("# QQMSN "). val (), email: $ ("# email "). val (), address: $ ("# address "). val ()},
DataType: 'html ',
Timeout: 1000,
Error: function () {alert ('unknown error, please contact QQ: 6434789. ');},
Success: function (data ){
If (data = "success "){
Alert ("registration successful! ");
Window. location. href = "/member/index. aspx ";
}
Else {
Alert ("registration failed because the user name has been registered! ");
}
}
});
Return (true );
}
Return (false );
}
// HTML page
Just make a form like this
Copy codeThe Code is as follows:
<Input id = "username" type = "text" onBlur = "checkname ()"/>
<Div class = d_default id = d_username> enter four or more English characters or numbers! </Div>
<Input id = "Button_ OK" type = "button" onclick = "return chk_reguser ();"/>
// RegisterOK. aspx. cs
Copy codeThe Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using BLL;
Public partial class registerOK: System. Web. UI. Page
{
User = new user ();
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
String lb = Request ["lb"];
String username = Request ["username"];
String password = Request ["password"];
String question = Request ["question"];
String answer = Request ["answer"];
String xqcode = Request ["xqcode"];
String realname = Request ["realname"];
String sex = Request ["sex"];
String tel = Request ["tel"];
String QQMSN = Request ["QQMSN"];
String email = Request ["email"];
String address = Request ["address"];
If (lb = "checkname ")
{
Response. Write (user. CheckUserName (username ));
}
If (lb = "reguser ")
{
String name = user. CheckUserName (username );
If (name = "congratulations, this user name can be registered! ")
{
User. Add (username, password, question, answer, xqcode, realname, sex, tel, QQMSN, email, address );
Response. Write ("success ");
}
Else
{
Response. Write ("fail ");
}
}
}
}
}
Note: registerOK. the aspx Page must clear all HTML code, for example, only <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "registerOK. aspx. cs "Inherits =" registerOK "%>.