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

    How to validate Textbox to allow only website url

    Hi,
    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 "http://www.google.com".

    If user insert "http://www.codeproject.com/Articles/334310/Understanding-ASP-NET-Validation-Techniques" then it should not allow.

    Allowed:-"http://www.google.com"

    Not Allowed:-"http://www.codeproject.com/Articles/334310/Understanding-ASP-NET-Validation-Techniques"
  • #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.

    Try

    @^(http\:\/\/|https\:\/\/)?([a-z0-9][a-z0-9\-]*\.)
    +[a-z0-9][a-z0-9\-]*$@i

    Regards

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762316
    Hi

    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 :kumaraspcode2009@gmail.com

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


Sign In to post your comments