Pages

Men

rh

4/10/2014

Validation for Text Box should accept Numbers and Charcters in C#

NameSpace : System.Text.RegularExpression

 In Class File we can write in the below....

public bool  IsAlphaNumeric(string inputString)
        {
           
            Regex r = new Regex("^[a-zA-Z0-9]+$");
            if (r.IsMatch(inputString))
                return true;
            else
                return false;
        }


In C#/............................

bool blLoginNameStatus;
CommonFunctions objCommon = new CommonFunctions() ;

blLoginNameStatus = objCommon.IsAlphaNumeric(txtLoginName.Text.ToString().Trim());

                if (blLoginNameStatus == false)
                {
                    lblErrMsg.Text = "";
                    lblErrMsg.Visible = true;
                    lblErrMsg.Text = "Please enter Login Name with combination of Letter, Numbers.";
                    lblErrMsg.ForeColor = System.Drawing.Color.Red;
                    txtLoginName.Focus();
                    txtLoginName.Text = "";
                    return false;
                }
                else
                {
                }

No comments :

Post a Comment