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

3 Answers

0 votes
const str: string = 'typescript 8046';
 
const character: any = str[11];
 
if (!isNaN(character * 1)) {
    console.log('character is numeric');
}
 
   
   
/*
run:
         
"character is numeric" 
       
*/

 



answered Mar 14, 2024 by avibootz
0 votes
const str: string = 'typescript 8046';
 
const character: any = str[11];
 
if (character >= '0' && character <= '9') {
    console.log('character is numeric');
}
 
   
   
/*
run:
         
"character is numeric" 
       
*/

 



answered Mar 14, 2024 by avibootz
0 votes
function isnumeric(ch: string) {
    return  ch.match(/[0-9]/i);
}
 
const str: string = 'typescript 8046';
 
const character: any = str[11];
 
if (isnumeric(character)) {
    console.log('character is numeric');
}
 
   
   
/*
run:
         
"character is numeric" 
       
*/

 



answered Mar 14, 2024 by avibootz

Related questions

3 answers 340 views
1 answer 227 views
2 answers 286 views
2 answers 274 views
2 answers 292 views
3 answers 380 views
3 answers 477 views
...