gfX Posted June 21, 2006 Share Posted June 21, 2006 Here is what I have:[code]if(eregi("'", $_POST['fn'])) { $error[] = "<strong class=\"error\">You entered an invalid character.</strong>"; $show = 'y'; }[/code]How would I make it so I can have a bunch of characters listed in that one line. Like I want ' " ! @ # $% ^ & * ( ) : ; {} [ ] > < etc. to have an error if entered. right now it only gives the error for the symbol 'it always messes up if I try to add the rest in there, with commas or whatever. I dont know the formula its supposed to go inanyone know? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 21, 2006 Share Posted June 21, 2006 [code]if (preg_match('/\'|"|\!|@|#|\$|%|\^|&|\*|\(|)|:|;|\{|}|\[]|>|</', $_POST['fn'])){ $error[] = "<strong class=\"error\">You entered an invalid character.</strong>"; $show = 'y';}[/code]It woudl look something like that - someone will come up with a more elegant solution I am sure oh and correct my regular expression too - just woke up so not firing on cylinders yet. Quote Link to comment Share on other sites More sharing options...
gfX Posted June 21, 2006 Author Share Posted June 21, 2006 Thanks for your reply, However for some reason it is not working. And it is allowing me to add folders with those characters in it.And when I don't type anything and I just hit enter - This is what I get:Warning: preg_match(): Compilation failed: unmatched parentheses at offset 27 in /**/**/gallery.php on line 1661. You must enter a folder name.Edit:Nevermind I Ijust took those parenthesis out and it works fine. Thanks so much Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 21, 2006 Share Posted June 21, 2006 [!--quoteo(post=386293:date=Jun 21 2006, 01:47 AM:name=gfX)--][div class=\'quotetop\']QUOTE(gfX @ Jun 21 2006, 01:47 AM) [snapback]386293[/snapback][/div][div class=\'quotemain\'][!--quotec--]How would I make it so I can have a bunch of characters listed in that one line. Like I want ' " ! @ # $% ^ & * ( ) : ; {} [ ] > < etc. to have an error if entered. right now it only gives the error for the symbol '[/quote]first off, i'm going to move this thread over to the regex forum so you'll get more help.second, try the following... if you create a character family, you can list them all together and let it match any of them:[code]<?phpif (preg_match('|[\'"\!@#\$%\^&\*\(\):;\{\}\[\]<>]|', $string)) { echo "Invalid character present!";}?>[/code]now, it sounds like you may be better off to match for [i]correct[/i] characters rather than incorrect. for instance, if i want to allow only letters, numbers and underscores, i simply have to do the following:[code]<?phpif (!preg_match('|^[a-z0-9_]+$|i', $string)) { echo "Invalid character present!";}?>[/code]hope this helps! 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.