1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regular expression for English characters

Discussion in 'PHP' started by shabbir, Jun 28, 2007.

  1. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Can anybody help me in developing the regular expression for PHP that will help me to detect if the string has any English characters. What I mean by English characters is A-Z, a-z, 0-9 and all the other symbols on keyboard + some extra ones that are used frequently. I am not very good at regular expression.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Yes, sure!

    PHP:
    if(preg_match('/[a-z0-9_-]+/',$stringWhereToCheck))
      print 
    "Has english chars";
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    What about the
    Code:
    !@#$%^&*()_+<>,.?/"':;{[]}\|
    as far as I can remember.
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Any english word must have a-z to be a valid word, special characters may or may not be there!
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    But my concern is it can have the string as :) : ) only also.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Can you tell me what are the special characters in
    Code:
    !@#$%^&*()_+<>,.?/"':;{[]}\|
    so that I can add the backslash. As far as I can get
    Code:
    $ , . { [ ] } \ 
    Am I missing something?
     

Share This Page