Javascript function that is equivalent for PHP function -


this question has answer here:

i have follwing code in php:

if(is_numeric($first_name[0]) === true){    //do } 

how able same check using javascript? php script check if there number in $first_name @ all, don't want user add number in first or last names please?

use regular expressions.

if (/-?\d+(?:\.\d*)?(?:[ee][+\-]?\d+)?/.test(yourinput)) {    // } 

of course, work on strings. different method, see duplicate question:

function isnumber(n) {   return !isnan(parsefloat(n)) && isfinite(n); } 

to check if input contains number (0-9) @ all, regex works again:

if (/[0-9]+/.test(yourinput)) {    // } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -