SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    North Carolina
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick Question on Regular Expressions

    I'm not that great at regular expressions, in fact, I know nothing about them. Of course I could learn it, but not enough time right now.

    Anyways, my question is this:

    If I have a variable $aNumber that equals "555a" or some other number/letter combination, how can I test it to see if it is all numbers or not?

    Also, If I have a variable $aString that equals "aaa5", how can I test it to see if it is all letters or not?

    The reason I ask is, I don't want people putting in any numbers in as their name, and I don't want people putting any letters in as their SSN.

    Thanks in advance.

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to check if something is all numbers:

    PHP Code:
    if (preg_match('/^\\d+$/'$txt)) { /* it's all numbers */ 
    all letters:

    PHP Code:
    if (preg_match('/^[a-z]+$/i'$txt)) { /* all letters */ 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    North Carolina
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot, worked great.


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
  •