wright67uk Posted April 26, 2011 Share Posted April 26, 2011 Can anybody help me with the preg match in my code; elseif ($Website == '' or (preg_match ("[a-zA-Z0-9\-\.]+\.(com|COM|Com|ORG|Org|org|net|NET|Net|edu|EDU|Edu|org|ORG|Org|NET|net|Net|co.uk|CO.UK|Co.uk|Co.Uk|co.Uk|CO.uk|co.UK", $Website))) I have the error; Warning: preg_match() [function.preg-match]: Unknown modifier '+' <?php //code selected if(isset($_POST['submit'])) { $drop = mysql_real_escape_string($_POST['drop_1']); $tier_two = mysql_real_escape_string($_POST['Subtype']); $Name = mysql_real_escape_string($_POST["Name"]); $Phone = mysql_real_escape_string($_POST["Phone"]); $Email = mysql_real_escape_string($_POST["Email"]); $Postcode = mysql_real_escape_string($_POST["Postcode"]); $Website = mysql_real_escape_string($_POST["Website"]); if($Name == '') { die('<br> You did not complete the name field, please try again'); } elseif ($Phone == '' or (preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone))) { //LINE74 die('<br> You completed the telephone field incorrectly, please try again'); } elseif ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL))) { die('<br> You completed the Email field incorrectly, please try again'); } elseif ($Postcode == '' or (!checkPostcode($Postcode))) { die('<br> You did not complete the Postcode field correctly, please try again'); } elseif ($Website == '' or (preg_match ("[a-zA-Z0-9\-\.]+\.(com|COM|Com|ORG|Org|org|net|NET|Net|edu|EDU|Edu|org|ORG|Org|NET|net|Net|co.uk|CO.UK|Co.uk|Co.Uk|co.Uk|CO.uk|co.UK", $Website))) { die('<br>You completed the website field incorrectly, please try again'); } else { echo("Thankyou for submiting your details, you will be added to our directory shortly"); }} Quote Link to comment Share on other sites More sharing options...
.josh Posted April 27, 2011 Share Posted April 27, 2011 preg_match expects the pattern argument to be formatted as such: "[delimiter][pattern][delimiter][modifier]" The delimiter separates the pattern from any modifiers you might have. It can be pretty much any non-alphanumeric character you want, as long as you remember to escape it if you use it as part of your actual pattern. So for instance, you need to do "~pattern~modifier" or "/pattern/modifier" But you don't actually have any modifiers in there so You just need to do like "~pattern~" So the reason you got that specific error is that you can use [ and ] as the pattern delimiter, so it's seeing your [ at the start of your pattern, then seeing the ] later on and thinking it's the end of your pattern and then thinks what comes next is are modifiers and since the next thing is a + and that's not a valid modifier, it throws an error. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 27, 2011 Author Share Posted April 27, 2011 (preg_match ("~a-zA-Z0-9-\.+\.com|COM|Com|ORG|Org|org|net|NET|Net|edu|EDU|Edu|org|ORG|Org|NET|net|Net|co.uk|CO.UK|Co.uk|Co.Uk|co.Uk|CO.uk|co.UK~", $Website)) is that what you mean? Will this be ok for checking say for example; www.mysite.com ? Quote Link to comment Share on other sites More sharing options...
requinix Posted April 27, 2011 Share Posted April 27, 2011 It won't work for .CoM or .EDu or .nET... Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 27, 2011 Author Share Posted April 27, 2011 Yep thats fine, I can add to the domain part. The only thing is that I get an error; Parse error: syntax error, unexpected ')' on line 112. I dont have a ')' on line 112. Ive commented on line 112. Im very new to regex / pregmatch etc. <?php function checkPostcode (&$toCheck) { $alpha1 = "[abcdefghijklmnoprstuwyz]"; $alpha2 = "[abcdefghklmnopqrstuvwxy]"; $alpha3 = "[abcdefghjkstuw]"; $alpha4 = "[abehmnprvwxy]"; $alpha5 = "[abdefghjlnpqrstuwxyz]"; $pcexp[0] = '^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$'; $pcexp[1] = '^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$'; $pcexp[2] = '^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$'; $pcexp[3] = '^(gir)(0aa)$'; $pcexp[4] = '^(bfpo)([0-9]{1,4})$'; $pcexp[5] = '^(bfpo)(c\/o[0-9]{1,3})$'; $Postcode = strtolower($toCheck); $Postcode = str_replace (' ', '', $Postcode); $valid = false; foreach ($pcexp as $regexp) { if (ereg($regexp,$Postcode, $matches)) { $toCheck = strtoupper ($matches[1] . ' ' . $matches [2]); $toCheck = ereg_replace ('C\/O', 'c/o ', $toCheck); $valid = true; break; } } if ($valid){return true;} else {return false;}; } if(isset($_POST['submit'])) { $drop = mysql_real_escape_string($_POST['drop_1']); $tier_two = mysql_real_escape_string($_POST['Subtype']); $Name = mysql_real_escape_string($_POST["Name"]); $Phone = mysql_real_escape_string($_POST["Phone"]); $Email = mysql_real_escape_string($_POST["Email"]); $Postcode = mysql_real_escape_string($_POST["Postcode"]); $Website = mysql_real_escape_string($_POST["Website"]); if($Name == '') { die('<br> You did not complete the name field, please try again'); } elseif ($Phone == '' or (preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone))) { //LINE74 die('<br> You completed the telephone field incorrectly, please try again'); } elseif ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL))) { die('<br> You completed the Email field incorrectly, please try again'); } elseif ($Postcode == '' or (!checkPostcode($Postcode))) { die('<br> You did not complete the Postcode field correctly, please try again'); } elseif ($Website == '' or (preg_match ("~a-zA-Z0-9-\.+\.com|COM|Com|ORG|Org|org|net|NET|Net|edu|EDU|Edu|org|ORG|Org|NET|net|Net|co.uk|CO.UK|Co.uk|Co.Uk|co.Uk|CO.uk|co.UK~", $Website))) { //THIS IS LINE 112 THIS IS LINE 112 die('<br>You completed the website field incorrectly, please try again'); } else { echo("Thankyou for submiting your details, you will be added to our directory shortly"); }} $query = ("INSERT INTO business (`id`, `Name`, `Type`, `Subtype`, `Phone`, `Email`, `Postcode`, `WebAddress`) VALUES ('NULL', '$Name', '$drop', '$tier_two' , '$Phone', '$Email', '$Postcode', '$Website')"); mysql_query($query) or die ( "<br>Query: $query<br>Error: " .mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 It parses without error for me. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 27, 2011 Author Share Posted April 27, 2011 I'm starting to get really fed up with GODADDY and the fact that my PHP files take sometimes 10 minutes to update on my server. Does anybody else have similiar problems with this or other hosting companies? Also, what board should I post this on if Id like to start a new thread? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 I've used them and never had that problem. Are you using FTP, or their shitty file manager? Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 27, 2011 Author Share Posted April 27, 2011 Im using their shitty ftp file manager Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 I hate that piece of garbage. I suspect if you use a regular FTP client, you'll have better results. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 27, 2011 Author Share Posted April 27, 2011 thankyou I shall find one. I managed to add ; www.hityu.com and then www.hityu.coy to my database . How can I change my code to only accept tld's that I listed within my expression in the code above? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 If it were me, I'd Google for a URL validation regex pattern and modifiy it instead of writing one, but I'm not a big fan of reinventing the wheel . . . Quote Link to comment Share on other sites More sharing options...
requinix Posted April 27, 2011 Share Posted April 27, 2011 A 100% accurate email regex is nearly impossible to do. I came up with this one a few months ago, but I'm not sure that it's perfect, and damned if I ever have to troubleshoot it... And what's to stop me from entering "foo@bar.com"? If I want to give a fake email then I will. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 27, 2011 Author Share Posted April 27, 2011 I see your point, but im not overly worried. Im making a directory and just want each listing to have a similiar format. If the user doesnt type in their own email address, they dont get enquiries. My email field is using FILTER_VALIDATE_EMAIL but its the website address that im working on at the moment. Im not sure if php has inbuilt filters for web addresses/url's??? Quote Link to comment Share on other sites More sharing options...
.josh Posted April 27, 2011 Share Posted April 27, 2011 filter_var FILTER_VALIDATE_URL Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 Built-in validate filters, but I haven't had great results from any of them, really. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 28, 2011 Author Share Posted April 28, 2011 but as im using this in a form, wouldnt my user have to type in http://www.mysite.com opposed to www.mysite.com? Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 29, 2011 Author Share Posted April 29, 2011 I got this to work well in my script in the end. Just thought i'd share it. I had a comment about COM com cOm and didnt realise that if i add 'i' at the end of my closing bracket that it would allow case to be ignored. elseif ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website))) { die('<br>You completed the website field incorrectly, please try again'); } 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.