Validating Price Text Field

Discussion in 'ASP.NET / ASP.NET Core' started by JJslim, Dec 25, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I was wondering how I can make sure the user inputs a money value into a text field? What would be the validation expression so that they would have to enter a say '0.01' for a penny?

    Thanks,
    Jarrod
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Try this

    ^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Hey Bruce, Regular Expressions are defintely my weak point, have been for years. Is there a good tutorial text on them you would like to recommend? For example that string is uncomprehensible to me. /emoticons/confused.gif
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    There are tons of website that gives intro to reg exp. Try a search in Google.

    Once you get a hang of regular expression, this website is good for testing or find other regular expression, http://www.regexlib.com/

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. Thanks, I've written some very short ones over the years and some I've seen can do what pages of code can but look like a candidate for an encryption contest. /emoticons/smile.gif
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page