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 198 views
1 answer 148 views
2 answers 167 views
2 answers 152 views
2 answers 169 views
3 answers 203 views
3 answers 321 views
...