Is numeric
There is no built-in is_numeric() function in JavaScript as there is in PHP. However, here is a simple is_numeric() function that you can copy and paste into your JavaScript:
The Function
function is_numeric(input){
return typeof(input)=='number';
}
Warning! is_numeric() doesn't always work if you are validating form input! This is because form inputs are strings, even if the user typed a number.
When validating form input, use this:
function form_input_is_numeric(input){
return !isNaN(input);
}
8e3a8f3d-06fd-41a8-8cbd-e0a2f615cbad
Created on: 12th October, 2022
Last updated: 12th October, 2022
Tagged With: