Skip to content

Instantly share code, notes, and snippets.

@bfodeke
Created June 13, 2015 15:19
Show Gist options
  • Save bfodeke/fa70775dce9a8861b525 to your computer and use it in GitHub Desktop.
Save bfodeke/fa70775dce9a8861b525 to your computer and use it in GitHub Desktop.
// Javascript price Regex
// Should work for the following prices.
var validPrices = ['90.99', '23', '231123.90', '90.00', '990,000.90', '$99.903', '$99,000.00'];
// Should fail for the following.
var invalidPrices = ['90,99', '993.999', '99,99.90'];
// Regex I have so far.
var priceRegex = /^\d+(\.\d{2})?$/;
validPrices.forEach( function (price) {
console.log(priceRegex.test(price));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment