-2

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
  • 557
  • 3
  • 17

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
  • 14,471
  • 7
  • 86
  • 95
-1

Regex to detect if last value is an integer:

^.*(\d)$

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