JavaScript, AJAX authentication

Source: Internet
Author: User

<script type= "Text/javascript" >

function username () {

$ (' #msg1 '). Remove ();

var username = $ ("#Username"). Val ();

var reg = new RegExp ("^ ([A-Z-A-Z u4e00-u9fa5]{4,16})");

if (username = = NULL | | username = = "") {

$ (' #Username '). After ("<b id= ' MSG1 ' >" + "username cannot be empty! "+" </b> ");

return false;

}

else if (!reg.exec (username)) {

$ (' #Username '). After ("<b id= ' MSG1 ' >" + "username can only be used in Chinese, English, numerals, underscores, 4-16 characters! "+" </b> ");

return false;

}

else {

return true;

}

}

function password () {

$ (' #msg1 '). Remove ();

var password = $ ("#Password"). Val ();

if (password = = NULL | | password = = "") {

$ (' #Password '). After ("<b id= ' MSG1 ' >" + "password cannot be empty! "+" </b> ");

return false;

}

else {

return true;

}

}

function ConfirmPassword () {

$ (' #msg1 '). Remove ();

var password = $ ("#Password"). Val ();

var Comfirmpassword = $ ("#ConfrimPassword"). Val ();

if (Comfirmpassword = = NULL | | comfirmpassword = = "") {

$ (' #ConfrimPassword '). After ("<b id= ' MSG1 ' >" + "Confirm password cannot be empty! "+" </b> ");

return false;

}

else if (comfirmpassword! = password) {

$ (' #ConfrimPassword '). After ("<b id= ' MSG1 ' >" + "two times password input inconsistent! "+" </b> ");

return false;

}

else {

return true;

}

}

function telephone () {

$ (' #msg1 '). Remove ();

var telephone = $ ("#Telephone"). Val ();

var reg = new RegExp ("^ (13[0-9]{9}) | ( 14[0-9]) | (18[0-9]) | (15[0-9][0-9]{8}) $ ");

if (telephone = = NULL | | telephone = = "") {

$ (' #Telephone '). After ("<b id= ' MSG1 ' >" + "phone number cannot be empty! "+" </b> ");

return false;

}

else if (!reg.exec (telephone)) {

$ (' #Telephone '). After ("<b id= ' MSG1 ' >" + "phone number is not formatted correctly! "+" </b> ");

return false;

}

else {

return true;

}

}

function email () {

$ (' #msg1 '). Remove ();

var email = $ ("#Email"). Val ();

var reg = new RegExp ("^ ([a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + ((\.[ a-za-z0-9_-]{2,3}) ($ ");

if (email = = NULL | | email = = "") {

$ (' #Email '). After ("<b id= ' MSG1 ' >" + "Mailbox cannot be empty! "+" </b> ");

return false;

}

else if (!reg.exec (email)) {

$ (' #Email '). After ("<b id= ' MSG1 ' >" + "Mailbox format is incorrect! "+" </b> ");

return false;

}

else {

return true;

}

}

var returnvalue = false;

function Registeryanzheng () {

var username = $ ("#Username"). Val ();

var Quanxian = $ ("#DropDownListPermission"). Val ();

var a = "User name or permission exists";

$.ajax ({

Type: "POST",

URL: "Register.aspx?action=ajax",

Data: "Z_username=" + username + "&&z_permission=" + Quanxian,

Success:function (msg) {

$ (' #msg1 '). Remove ();

$ ("#Submit"). attr ("disabled", false);

if (Msg.indexof (a) >-1) {

$ (' #DropDownListPermission '). After ("<b id= ' MSG1 ' >" + msg + "</b>");

Determine if the button is available

$ ("#Submit"). attr ("Disabled", true);

ReturnValue = false;

}

else {

$ ("#Submit"). attr ("disabled", false);

ReturnValue = true;

}

}

});

}

function Yanzheng () {

if (!username ()) {

return false;

}

if (!password ()) {

return false;

}

if (!confirmpassword ()) {

return false;

}

if (!telephone ()) {

return false;

}

if (!email ()) {

return false;

}

if (!registeryanzheng ()) {

Registeryanzheng ();

Return returnvalue;

}

else {

return true;

}

}

</script>

Background:

if (! String.IsNullOrEmpty (request["Action"]) && request["action"] = = "Ajax")

{

String username = request["Z_username"];

string permission = request["Z_permission"];

SqlConnection conn = new SqlConnection (URL);

Conn. Open ();

Try

{

SqlCommand cmd = new SqlCommand ();

DataTable dt = new DataTable ();

Cmd.commandtext = "SELECT * from zmt_user where z_username = '" + Username + "'"

+ "and z_permission = '" + permission + "'";

Cmd. Connection = conn;

SqlDataAdapter SDA = new SqlDataAdapter (cmd);

Sda. Fill (DT);

if (dt. Rows.Count > 0)

{

Response.Write ("User name or permission exists");

System.Threading.Thread.Sleep (2000);

}

else {

Response.Write ("does not exist");

}

}

catch (Exception ex)

{

Console.WriteLine ("Error");

}

Finally

{

Response.End ();

Conn. Close ();

}

Response.End ();

}

Note the receipt of the return value

JavaScript, AJAX authentication

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.