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 6 of 6
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Form Validation - Validate link

    Hi there, I've been having great difficulty using regex to validate a link that's been input via a form.

    I've had a look at the few examples that I've found on here (and elsewhere), but they just don't work for me. The main problem I think, is that most are not geared towards dynamic links, only static ones.

    I'm not too concerned about making sure that the link is valid, just making sure that the users can only input allowed characters really.

    This is what I came up with:

    PHP Code:
    if (!eregi("^[[:alnum:][:punct:]\+/\?=&]{12,255}$"$_POST['link'])){
    //problem
    } else {
    //no problem

    Can anyone tell me what's wrong with this and why it won't work for me?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'd recommend this thread for the regex.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,455
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    Try this ... using $_REQUEST will handle all ... GET/POST/URL variable.


    $test=$_REQUEST['link'];

    if (!eregi("^[[:alnum:][unct:]\+/\?=&]{12,255}$", $test)){
    //problem
    } else {
    //no problem
    }

  • #4
    New Coder
    Join Date
    May 2005
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar View Post
    I'd recommend this thread for the regex.
    Thanks Marek_mar, I had tried all those. But you made me double check the name of the variable, and the name that was posted and the name that was validated were different. School Boy error

    @mlseim - how is that even vaguely relevant?

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Did you ttry that one I made?
    Can you post the regex&URL that failed to match?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,455
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    I tried your exact script and it works fine for me.

    I thought maybe on your form you're not using POST.
    But we can't see your form, so I suggested using $_REQUEST,
    ... won't matter if you use POST or GET on your form.


  •  

    Posting Permissions

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