Home > OS >  How to check if string starts with number and does not contain any substring with it in javascript?
How to check if string starts with number and does not contain any substring with it in javascript?

Time:12-09

I want to check if the first element of the string is number and if it is number then there should not be any word attached with this number. Following is an example to make it clear:

function startsWithNumber(str) {
  return /^\d/.test(str);
}

// Actual Output
console.log(startsWithNumber('123avocado')); //            
  • Related