How to check if a string ends with a number in TypeScript

1 Answer

0 votes
function stringEndsWithNumber(str : string) : any {
    return /[0-9]+$/.test(str);
}
  
console.log(stringEndsWithNumber('typescript 2022 2023')); 
console.log(stringEndsWithNumber('15F')); 
console.log(stringEndsWithNumber('PI3.14')); 
 
 
 
 
 
/*
run:
  
rue
false
true
  
*/

 



answered Jun 6, 2022 by avibootz
...