If you want to read and understand it, you can read it a bit. If you only need the results, skip to the end of this article.
Later on the internet to find a lot, even some foreigners, including some of the Pure English Forum, found all is wrong, are not comprehensive.
A casual look will know, if the front with + is wrong, if there is no decimal point is wrong, if 00.123 also good newspaper and so on
Almost like the last one.
3. /^\d*+ (\.\d+)? $/ The same page as the previous one
There seems to be a lot of levels, such as the decimal point and after the decimal point can have no (that is, integers can, not just decimal fraction)
But before the decimal point, 00.123 is also possible.
4. /^[+-]?\d+ (\.\d+) $/
is also better, such as considering the positive and negative signs, and so on, but the same decimal point before 00.123 is also possible
Don't look for more, that's probably the case.
Here is a notation I have tested several times:
var regExp =/^[+-]? (0| ([1-9]\d*)) (\.\d+)? $/g;var B = regexp.test (a); alert (b);
^$ matches the end of the string, respectively
[+-]? Indicates that the beginning of a string can have a + or-or no symbol, and there can be only one
0| [1-9]\d* This is the integer part before the decimal point, which indicates that it can be either (a 0) or (for a first-digit not 0 integer, but the first bit can be 0 later)
(\.\d+)? Refers to the decimal point and the back part of the decimal point, not appearing or appearing once
G all matches, (as if not required)
Therefore, the perfect match for the decimal type.