javascript regex decimal -
var re = /^([0-9]*)(\.[0-9]{2})$/ re.test(.22) true re.test(.20) false re.test(10.02) true re.test(10.00) false
i want pass 10.00, 10.02, 10.20. looks passing 10.02.
what doing wrong?
the trailing zeroes truncated when automatic string conversion done during call test()
. use tofixed()
string conversion manually instead.
for example:
var re = /^([0-9]*)(\.[0-9]{2})$/; re.test((.22).tofixed(2)); //true re.test((.20).tofixed(2)); //true re.test((10.02).tofixed(2)); //true re.test((10.20).tofixed(2)); //true re.test((10.00).tofixed(2)); //true
Comments
Post a Comment