www.webdeveloper.com
Results 1 to 4 of 4

Thread: regular expression price validation

  1. #1
    Join Date
    Oct 2009
    Posts
    65

    regular expression price validation

    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?

  2. #2
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    373
    /^(0\.|[1-9]\d*\.)d{2}/ should answer your first question.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You may simply use the Number() method to correct the value onblur. Rough code (you may use a function instead, if you want):
    Code:
    <input type="text" onblur="this.value=Number(this.value)">
    Last edited by Kor; 04-07-2011 at 08:14 AM.

  4. #4
    Join Date
    Oct 2009
    Posts
    65
    Thanks! Couple of small changes /^\d+\.\d{2}$/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles