Validate if a given string is numeric.
Some examples:
"0"
=> true
" 0.1 "
=> true
"abc"
=> false
"1 a"
=> false
"2e10"
=> true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
需要考虑的情况太多了,我也分不清什么样的数字合法了。最后不得不求助互联网,搜集来的规则如下:
1、空格不能出现在数字之间
2、"."和e最多只能出现一次
3、e之前和之后必须有数字
4、正负号要么出现在数字的最前面,要么出现在紧接着e后面
5、正负号最多出现两次
6、"1.", ".34","+.1"也被认为是正确的