how to check the input value is decimal in javascript e.g 10000 ok 10000.11 ok 10000.111 not ok f10000 not ok aaaaaaaaaa not ok 1f000000 not ok
"joe" wrote in message news:D5009544-A87D-4B90-8241-304A1255296A@microsoft.com > how to check the input value is decimal in javascript > e.g > 10000 ok > 10000.11 ok > 10000.111 not ok > f10000 not ok > aaaaaaaaaa not ok > 1f000000 not ok var s = "10000.11"; if (isNaN(Number(s))) { // not a valid number } I don't quite understand why 10000.11 is OK with you but 10000.111 is not. Both look decimal enough to me. Both will pass the test above. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
i don't want it have more than two precision e.g xxx.xx ok xxx.xxx not ok "Igor Tandetnik" wrote: > "joe" wrote in message > news:D5009544-A87D-4B90-8241-304A1255296A@microsoft.com > > how to check the input value is decimal in javascript > > e.g > > 10000 ok > > 10000.11 ok > > 10000.111 not ok > > f10000 not ok > > aaaaaaaaaa not ok > > 1f000000 not ok > > var s = "10000.11"; > if (isNaN(Number(s))) { > // not a valid number > } > > I don't quite understand why 10000.11 is OK with you but 10000.111 is > not. Both look decimal enough to me. Both will pass the test above. > -- > With best wishes, > Igor Tandetnik > > With sufficient thrust, pigs fly just fine. However, this is not > necessarily a good idea. It is hard to be sure where they are going to > land, and it could be dangerous sitting under them as they fly > overhead. -- RFC 1925 > > >
"joe" wrote in message news:61844B5B-6753-4191-9E19-03A6A75104ED@microsoft.com > i don't want it have more than two precision > e.g > xxx.xx ok > xxx.xxx not ok Test your string against a regular expression. Something like this: var re = /^\s*\d+(\.\d{0,2})?\s*$/; var s = "123.45"; if (!re.test(s)) { // Not a valid number } -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
"precision" is part of the documentation "toPrecision" or such check your file. "joe" wrote in message news:61844B5B-6753-4191-9E19-03A6A75104ED@microsoft.com... > i don't want it have more than two precision > e.g > xxx.xx ok > xxx.xxx not ok > > > "Igor Tandetnik" wrote: > > > "joe" wrote in message > > news:D5009544-A87D-4B90-8241-304A1255296A@microsoft.com > > > how to check the input value is decimal in javascript > > > e.g > > > 10000 ok > > > 10000.11 ok > > > 10000.111 not ok > > > f10000 not ok > > > aaaaaaaaaa not ok > > > 1f000000 not ok > > > > var s = "10000.11"; > > if (isNaN(Number(s))) { > > // not a valid number > > } > > > > I don't quite understand why 10000.11 is OK with you but 10000.111 is > > not. Both look decimal enough to me. Both will pass the test above. > > -- > > With best wishes, > > Igor Tandetnik > > > > With sufficient thrust, pigs fly just fine. However, this is not > > necessarily a good idea. It is hard to be sure where they are going to > > land, and it could be dangerous sitting under them as they fly > > overhead. -- RFC 1925 > > > > > >