How to check if a character in a string is numeric with Node.js

3 Answers

0 votes
const str = 'node.js 1234';
 
const character = str[9];
 
if (!isNaN(character * 1)) {
    console.log('character is numeric');
}
 
   
   
/*
run:
         
character is numeric
       
*/

 



answered Mar 14, 2024 by avibootz
edited Mar 14, 2024 by avibootz
0 votes
const str = 'node.js 1234';
 
const character = str[9];
 
if (character >= '0' && character <= '9') {
    console.log('character is numeric');
}
 
   
   
/*
run:
         
character is numeric
       
*/

 



answered Mar 14, 2024 by avibootz
edited Mar 14, 2024 by avibootz
0 votes
function isnumeric(ch) {
    return ch.match(/[0-9]/i);
}
 
const str = 'node.js 1234';
 
const character = str[9];
 
if (isnumeric(character)) {
    console.log('character is numeric');
}
 
   
   
/*
run:
         
character is numeric
       
*/

 



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

Related questions

3 answers 185 views
1 answer 140 views
1 answer 143 views
1 answer 90 views
...