Jump to content

eregi help


gfX

Recommended Posts

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 in

anyone know?
Link to comment
https://forums.phpfreaks.com/topic/12517-eregi-help/
Share on other sites


[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.
Link to comment
https://forums.phpfreaks.com/topic/12517-eregi-help/#findComment-47944
Share on other sites

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 166
1. You must enter a folder name.

Edit:
Nevermind I Ijust took those parenthesis out and it works fine. Thanks so much
Link to comment
https://forums.phpfreaks.com/topic/12517-eregi-help/#findComment-47990
Share on other sites

[!--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]
<?php
if (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]
<?php
if (!preg_match('|^[a-z0-9_]+$|i', $string)) {
  echo "Invalid character present!";
}
?>
[/code]

hope this helps!
Link to comment
https://forums.phpfreaks.com/topic/12517-eregi-help/#findComment-47995
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.