Running the unit tests against the new code and it only fails on the infinity and boolean literals, and the only time that should be a problem is if you're generating code (really, who would type in a literal and check if it's numeric?You should I can't believe no one pointed out the use of a regular expression (replace) after warning about not using regular expressions...
If you can't use expression forces Java Script to do type coercion on your input value; it must first be interpreted as a number for the subtraction operation.
If that conversion to a number fails, the expression will result in result is then compared to the original value you passed in.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Since the left hand side is now numeric, type coercion is again used.
Now that the input from both sides was coerced to the same type from the same original value, you would think they should always be the same (always true).
You can write Java Script scripts to check the following validations.
To get a string contains only numbers (0-9) we use a regular expression (/^[0-9] $/) which allows only numbers.
To alleviate this problem, I added a check to discount arrays from the logic I then took CMSs 30 test cases and cloned the testing on jsfiddle added my extra test cases and my above described solution. it should be noted that it assumes that '.42' is NOT a number, and '4.' is NOT a number, so this should be taken into account.
It may not replace the widely accepted/used answer but if this is more of what you are expecting as results from your is Numeric function then hopefully this will be of some help. The idea here is that every number or integer has one "canonical" string representation, and every non-canonical representation should be rejected.
Next, the match() method of the string object is used to match the said regular expression against the input value. To get a string contains only numbers (0-9) with a optional or - sign (e.g.