WEB Please help with this regualar expression preg_match()

Discussion in 'OT Technology' started by nubian, Nov 18, 2009.

  1. nubian

    nubian Active Member

    Joined:
    Aug 11, 2003
    Messages:
    27,761
    Likes Received:
    1
    Is there anyway to force a specific string format?
    For example this requires numbers and no leading zeros.
    Code:
    ^[1-9][0-9]+$
    What I'm looking to do is force the end-user to enter the string 'lbs' (in that exact order) after the numbers so they'd be forced to enter say '125lbs'.
    Also for height, would it be possible to force the ' (hyphen) in a format like 5'11?
    Again, any help will greatly be appreciated.
     
    Last edited: Nov 18, 2009
  2. Krakerjak

    Krakerjak Active Member

    Joined:
    Jul 7, 2003
    Messages:
    8,288
    Likes Received:
    0
    Location:
    Edmonton eh
    ^[1-9]?[0-9]*\.?[0-9]+?\s*[l|L][b|B][s|S]$
    for the lbs thing

    this allows for decimals like "56.4 lbs"
    any of these would be valid
    44223 lbs
    2355lbs
    2345LBS
    453 Lbs
    4523 lbS
    13 lbs
    3.13 lbs
    1.0lbs
     
  3. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    you should NEVER force the user to enter formatting...

    ^([\d]+)$
    would return the number

    you should be asking for # in feet, then # in inches...not 5'11"
     
  4. nubian

    nubian Active Member

    Joined:
    Aug 11, 2003
    Messages:
    27,761
    Likes Received:
    1
    thank you both for your replies.
    i appreciate it.
    i failed to realize other units of measure. :uh:

    again thanks!
     

Share This Page