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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.