You must Sign In to post a response.
  • Category: ASP.NET

    How to restrict the user for not to enter only numbers in customer shipping address textbo

    Hi Friends,

    I am working on online shopping website...using vs 2010 . for entering the shipping address i have give alphanumeric character and special character... now i need to validate the address textbox for not to enter only number .. i need to give error message when ever user enter only numbers in texbox . plz help me for how to validate for the customer address

    Thanking u
  • #762851
    Hello Ambika,

    Refer the below code :

    <html xmlns="" >
    <head runat="server">
    <form id="form1" runat="server">
    Address :
    <asp:TextBox ID="TextBoxAddress" runat="server" TextMode="MultiLine"></asp:TextBox>
    <asp:Button ID="ButtonSubmit" runat="server" Text="Submit"
    onclick="ButtonSubmit_Click" />

    Code - behind :

    protected void ButtonSubmit_Click(object sender, EventArgs e)
    int parsedValue;
    if (int.TryParse(TextBoxAddress.Text, out parsedValue))
    Response.Write("<script>alert('" + Server.HtmlEncode("Textbox contains numbers only") + "')</script>");

    See the attached image. It's an output i have got using above code.

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #762855
    Hi Ambika.

    Use the regular expression validator for the address textbox.

    < asp:TextBox runat ="server" id ="txtaddress" />
    < asp:RegularExpressionValidator runat ="server"
    id="alphaNumeric" controltovalidate ="txtaddress"
    validationexpression=" ^[ A-Za-z0-9_@./#&+-] $"
    errormessage ="Please enter alphanumeric and special characters only" />

    Sridhar Thota.
    Editor: DNS Forum.

  • #762869
    Hi Ambika,
    Yes, you can use either JavaScript to handle it or the Regular Expression at server side or client side.

    using System.Text;
    if(!Regex.IsMatch(text, "^[ A-Za-z0-9_@./#&+-] $")
    // message

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

Sign In to post your comments