SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good grief. I can't make heads or tails of ereg.. can someone help clear my clouded brain?

    I am trying to test a string to see if it contains invalid characters. Here's what I have:

    invalid characters are " ,:=" (minus the quotes)

    Code:
    $string = "Monkey ,";
    if (ereg ("[^,:= ]", $string)) { echo "bad"; }
    else { echo "good"; }
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (ereg ("[,:= ]"$string)) { 
    echo(
    "bad");
    } else {
    echo(
    "good"); 
    this is assuming that you do NOT want spaces allowed. If you want spaces to be ALLOWED then try this:

    PHP Code:
    if (ereg ("[,:=]"$string)) { 
    echo(
    "bad");
    } else {
    echo(
    "good"); 
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to follow up on what exbabylon said. The reason your first one was failing is because of the ^ that means not ,:= so if it had one then it would fail thus printing your true statement.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •