Search This Blog

Friday, 5 August 2016

Asp.net allow only alpha numeric value in password validation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace passwordformat
{
    public partial class Loginpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            Regex alpha = new Regex("[a-z]");
            Regex numeric = new Regex("[0-9]");
            string password = Password.Text;
            string confirmPass = cnfPassword.Text;
            if (alpha.IsMatch(password) && numeric.IsMatch(password))
            {
                Successmessage.Text = "You are successfully registered";
                Successmessage.Visible = true;
                PasswordErrorMsg.Visible = false;
            }
            else
            {
                PasswordErrorMsg.Text = "Your password must be in alphanumeric";
                PasswordErrorMsg.Visible = true;
                Successmessage.Visible = false;
            }
        }
    }
}


1 comment:

  1. The Best Games On The Planet Online - Dr.MCD
    The Best Games On The Planet Online. by. 여주 출장샵 The best 창원 출장샵 game on the planet. The 광양 출장안마 best 양산 출장샵 time to play in casinos and the best online 청주 출장마사지 casino for fun!

    ReplyDelete