5
Reply

I want to create a text box where in i want to enter email address only. How to do that ?

sravanti rachala

sravanti rachala

13y
17.5k
0
Reply

    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                ControlToValidate="TBMailId" ErrorMessage="check ur mail id"
                style="z-index: 1; left: 452px; top: 549px; position: absolute"
                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

    Hi

    In your  C# Web Application,  In the aspx page  Use RegularExpressionValidator

    <asp:TextBox ID="TextBoxEmail" runat="server"><asp:TextBox>

    <asp:RegularExpressionValidator ID="RegularExpressionValidatorTextBoxEmail" ControlToValidate="TextBoxEmail"

    runat="server" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

    ErrorMessage="Enter valid Email"></asp:RegularExpressionValidator>

     

     

    Hi Sravanti,
    You can try the below code...
    string  Email_Expression;
            private void button1_Click(object sender, EventArgs e)
            {
                Email_Expression ="^[a-zA-Z][\\w\\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$" ;
                if (textBox1.Text != null)
                {
                    if (Regex.IsMatch(textBox1.Text, Email_Expression))
                        MessageBox.Show("You have entered Correct Email ID");
                    else
                        MessageBox.Show("Please Enter Email Correctly");
                }
            }

    Thanks & Regards
    Santosh D.M.R

    Hey You can use this code 


    /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,4}$/;

    In C# Web Application Use RegularExpressionValidator


    Select Property and Change

    ControlToValidate="textboxID" 
      ValidationExpression="^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$" 
                ErrorMessage="Please Enter  Email ID"