regular expression price validation

Discussion in 'JavaScript' started by bonecone, Apr 7, 2011.

  1. #1
    I'm trying to find a regular expression that will reject leading zeroes in a price unless the zero is the only digit before the decimal. So it will accept 0.03 but not 00.03 or 01.03.

    This is the best price validation I've been able to find so far /^\d+\.\d{2}$/

    How do I modify it?

    Also, how do I use regex replace to trim all leading zeroes from a price except for the the one next to the decimal?
     
    bonecone, Apr 7, 2011 IP
  2. Perpetual infinity

    Perpetual infinity Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    /^(?:\d?|[1-9]\d+)\.\d{2}$/
    Code (markup):
    I'm not sure about the latter half of your request though.
     
    Perpetual infinity, Apr 20, 2011 IP