I need a regular expression in javascript that will accept only positive numbers and decimals. This is what I have but something is wrong — it doesn’t seem to take single positive digits.
/^[-]?[0-9]+[\.]?[0-9]+$/;
For example, 9 will not work. How can I restructure this so if there is at least one positive digit, it will work?
matches
but not
EDIT:
To handle scientific notation (
1e6), you might want to doIf you want strictly positive numbers, no zero, you can do