SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    allow a space " "in an regular expression

    Hi there,

    How can ik allow a space in my regular expression:

    PHP Code:
    function checkSyntaxTussenvoegsel($string){
        
    $regexp="^[a-zA-Z.'-]{0,10}$";
        
        if(!
    ereg($regexp,$string)){
            return 
    false;
        }
        else{
            return 
    true;
        }


  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    \s is the character for a space.
    Sam Hastings

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SJH
    \s is the character for a space.
    Actually no, you simply use a space for a space. preg_match('/^[a-z ]+$/','a b c') returns 1. \s matches any whitespace character, such as a linebreak or a carriage return, or a tab. But yeah, it does match a space, too


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
  •