SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Number regex

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Number regex

    I am working on a regular expression that requires only a number for a dollar amount

    example 500.00

    Here is what I have: /[1-9]{3-5}(\.)[1-9]{2}$/

    It doesn't work though

    Id also like to add a dollar sign to the front

    example: $500.00

    Can someone help me write this

    Thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You left out zero from the valid numbers - that's why 500.00 is invalid.

    Try this:

    /^\$?[1-9]\d{2,4}\.\d{2}$/

    Take out the ? if you don't want the dollar sign to be optional.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help but still doesn't seem to work.

    http://kenaesthetic.com/rfp.htm

    Check estimated budget

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake it works. Thanks so much


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
  •