Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    236
    Thanks
    11
    Thanked 5 Times in 5 Posts

    preg_match validation on url - help please

    Hi huys i have a simple validation using preg_match.

    There is a couple of issues which i cant seem to get right.

    1. making it so: http:// to be or not to be!
    2. making a /page.php (www.domain.com/page.html)

    Here is the code i am using.

    PHP Code:
    if(!preg_match('#^https?://[a-z0-9-._]+\.[a-z0-9]{2,4}$#i'$authorsurl)){
        
    $errors[] = "Please Insert A Valid Website Url"

    Thanks in advance

  • #2
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    Probably the easiest way would be to simply not test for
    Code:
    https?://
    if you are going to allow both of these scenarios:

    Code:
    http://username.abc3
    https://username.abc3
    username.abc3
    but there may be side effects with that.

    I'm guessing you are populating $authorsurl from the requested URL and I would expect the mechanism which provides it to give the http|https regardless.

    Not quite sure what you mean by:
    2. making a /page.php (www.domain.com/page.html)

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    236
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by leslie.jones View Post
    Probably the easiest way would be to simply not test for
    Code:
    https?://
    if you are going to allow both of these scenarios:

    Code:
    http://username.abc3
    https://username.abc3
    username.abc3
    but there may be side effects with that.

    I'm guessing you are populating $authorsurl from the requested URL and I would expect the mechanism which provides it to give the http|https regardless.

    Not quite sure what you mean by:
    Thank you for the reply.

    The url will be from users submitting comments on my blog.

    and some people who link build use the http but normal people just use the www.

    I suppose i can just not test for it.

    The other issue which i did not come across very well is, if some posts a url/page it does not validate.

    For instance...

    www.domain.com/somepage.php

    Because its testing for domain.com anything after this is not being allowed to be submitted.

    I hope i was a little clearer now


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •