SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Expressions

    Hi,

    I'm trying to figure a method of disallowing certain characters in a variable.

    Say, the list:
    #&;'\"|*?~<>^()[]{}$

    How do I do that? Thanks for your help.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    /* Let's assume that your variable is called $foo */
    
    if (preg_match("/^[^#&;'\"|*?~<>\^()[\]{}$]+$/",$foo)) {
      //do bad variable format stuff
      //
      //
    }
    else {
      //format accepted
      //do other stuff here
    }

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Thanks! Great!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •