SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: ereg() allow

  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ereg() allow

    Hi,

    I know there is a 1000 regular expression threads, but I can't find one that answer my question, so here goes:

    I have this function to validate text
    PHP Code:
          function validateText($input){
                  
              
    $result ereg ("^[A-Za-z0-9_\ ]+$"$input );
              if (
    $result){
                  return 
    true;
              }else{
                  return 
    false
              }
          } 
    But I also want to allow characters such as . , - ' "
    How do I do that?

    Also, I would like to allow letters with or like and . How can that be done?

    Thanks for any help.

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2005
    Location
    Hegelsom, The Netherlands
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For . , - ' " you'd just use:

    PHP Code:
    function validateText($input){
        
    $result ereg ("^[-A-Za-z0-9_\ ,.'\"]+$"$input );
        if (
    $result){
             return 
    true;
        }else{
             return 
    false;
        }

    For the special characters I'd guess you'd have to use a special notation. You CAN try to just add them to the character class like:

    PHP Code:
    function validateText($input){
        
    $result ereg ("^[-A-Za-z0-9_\ ,.'\"]+$"$input );
        if (
    $result){
             return 
    true;
        }else{
             return 
    false;
        }

    Though this makes me wonder, wouldn't it be easier to exclude the characters you DONT want? Still hope it helps
    Yeap, I'm new here :P

    Game Insight

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, it works perfectly
    I don't know about the special characters, I'll experiment with that a bit

    Thanks for the help!


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
  •