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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -