chris_s_22 Posted November 30, 2009 Share Posted November 30, 2009 both of these are suposed to check url is in correct format? this should only alow http:// with domain name with no folder extentions if(!preg_match("/^http://[0-9a-zA-Z-.].[a-zA-Z]{2,3}$/", $_POST[linkto])) this should alow as above but with folder ext if(!preg_match("/^http://(www.[0-9a-zA-Z][0-9a-zA-Z-][0-9a-zA-Z]|[0-9a-zA-Z][0-9a-zA-Z-][0-9a-zA-Z]).[a-zA-Z]{2,3}[0-9a-zA-Z/-_.]$/", $_POST[linkfrom])) Quote Link to comment Share on other sites More sharing options...
cags Posted November 30, 2009 Share Posted November 30, 2009 I'm not entirely sure what your question is so I'm going to go ahead and just make some general comments. 1). $_POST[linkto] will (probably) throw a Notice level error. You should really change this to $_POST['linkto']. 2). Your pattern has no repeat metacharacter/sequence for the first character set meaning it will only match against a single character. 3). You then have an unescaped period/fullstop which will allow any single character. 4). You use your delimiter character in your pattern without escaping it. 5). 2 to 3 characters for the top level domain will not allow for urls such as http://something.info, which is a valid URL. 6). By using the exclamation mark, the if statement will only be entered if the string entered doesn't match the pattern. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.