Check if String contains any Letter in JavaScript-Code Examples

Radu TM

Check if String contains any Letter in JavaScript

JavaScript by Radu TM June 22, 2022

// check if string contains any letter in javascript

function checkString(str) {
  // regex to check if string contains any letter
  const regex = /[a-zA-Z]/;
  // return true if string contains any letter, false otherwise
  return regex.test(str);
}

// test the function
console.log(checkString("🍕")); // false
console.log(checkString("pizza")); // true

0

25.740

Check if String contains any Letter in JavaScript

JavaScript by Radu TM June 22, 2022

const string = "I ❤️ JS";

// check if string contains any letter
const hasLetter = /[a-zA-Z]/.test(string);

console.log(hasLetter); // true

0

25.740

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories