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

1 Answer

0 votes
function stringEndsWithNumber(str) {
    return /[0-9]+$/.test(str);
}
 
console.log(stringEndsWithNumber('javascript2022')); 
console.log(stringEndsWithNumber('35F')); 
console.log(stringEndsWithNumber('PI3.14')); 





/*
run:
 
rue
false
true
 
*/

 



answered Jun 6, 2022 by avibootz
...