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,375
    Likes Received:
    388
    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,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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,375
    Likes Received:
    388
    Trophy Points:
    83
    What about the
    Code:
    !@#$%^&*()_+<>,.?/"':;{[]}\|
    as far as I can remember.
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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,375
    Likes Received:
    388
    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,375
    Likes Received:
    388
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice