...

View Full Version : Form Validation - Validate link



Snetty
11-01-2006, 02:04 PM
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:



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?

marek_mar
11-01-2006, 02:43 PM
I'd recommend this thread (http://www.codingforums.com/showthread.php?t=76949) for the regex.

mlseim
11-01-2006, 03:01 PM
Try this ... using $_REQUEST will handle all ... GET/POST/URL variable.


$test=$_REQUEST['link'];

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

Snetty
11-01-2006, 03:22 PM
I'd recommend this thread (http://www.codingforums.com/showthread.php?t=76949) 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?

marek_mar
11-01-2006, 07:14 PM
Did you ttry that one I made?
Can you post the regex&URL that failed to match?

mlseim
11-01-2006, 07:23 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum