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

    How to validate Textbox to allow only website url

    I need to validate textbox so that it can only take website url up-to domain code only.
    For e.g. User must insert website url as "".

    If user insert "" then it should not allow.


    Not Allowed:-""
  • #762310
    Hi Prafull.

    Try the regular expression validator with the following regax.

    ^www[.][a-z]{ 1 ,15 }[.](com|org)$ // it will allow only the domain names having minimum one character and maximum 15 characters.




    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762316

    You can try this Code for Url validation part

    <asp:TextBox ID="TxtUrl" runat="server" Width="1000px" ></asp:TextBox>

    <asp:RegularExpressionValidator ID="reg" runat="server" ControlToValidate="TxtUrl" ErrorMessage="*" ForeColor="Red"
    ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"></asp:RegularExpressionValidator>

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • Sign In to post your comments