-1

please advice on how to check if a string ends with any integer at all in javascript. Not a specific integer.

e.g aahdhs7; //Returns true assa4; //also returns true

Thank you

Willower
  • 1,099
  • 8
  • 22

2 Answers2

0

try Number.isNumber()

my_str = "Hi Hello 3";
my_str1 = "Hi Hello";

console.log(Number.isInteger(parseInt(my_str.substr(-1))));
console.log(Number.isInteger(parseInt(my_str1.substr(-1))));
Mohideen bin Mohammed
  • 18,813
  • 10
  • 112
  • 118
-1

Regex to detect if last value is an integer:

^.*(\d)$

Example here - https://regexr.com/3mk0q