How to check if a character in a string is numeric with JavaScript

3 Answers

0 votes
const str = 'javascript 890';

const character = str[12];

if (!isNaN(character * 1)) {
    console.log('character is numeric');
}

  
  
/*
run:
        
character is numeric
      
*/

 



answered Mar 13, 2024 by avibootz
edited Mar 14, 2024 by avibootz
0 votes
const str = 'javascript 890';

const character = str[12];

if (character >= '0' && character <= '9') {
    console.log('character is numeric');
}

  
  
/*
run:
        
character is numeric
      
*/

 



answered Mar 13, 2024 by avibootz
edited Mar 14, 2024 by avibootz
0 votes
function isnumeric(ch) {
    return  ch.match(/[0-9]/i);
}

const str = 'javascript 890';

const character = str[12];

if (isnumeric(character)) {
    console.log('character is numeric');
}

  
  
/*
run:
        
character is numeric
      
*/

 



answered Mar 13, 2024 by avibootz
edited Mar 14, 2024 by avibootz

Related questions

2 answers 168 views
2 answers 152 views
2 answers 170 views
3 answers 221 views
3 answers 203 views
1 answer 157 views
157 views asked Aug 17, 2019 by avibootz
1 answer 167 views
...