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 338 views
1 answer 226 views
2 answers 283 views
2 answers 274 views
2 answers 287 views
3 answers 375 views
3 answers 473 views
...