[LeetCode][JavaScript]Valid Number
Valid Number
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.
https://leetcode.com/problems/valid-number/
正则技术哪家强
1 /** 2 * @param {string} s 3 * @return {boolean} 4 */ 5 var isNumber = function(s) { 6 s = s.trim(); 7 if(s !== "" && /^[-+]?(\d+\.?|\.\d+)\d*([e|E][-+]?\d+)?$/.test(s)){ 8 return true; 9 } 10 return false; 11 };