EasyRegex Logo
EasyRegex
New

Match Only Letters and Spaces in JavaScript

javascript

Regular Expression

^[a-zA-Z\s]+$
Copy
Do you have Feedback?

Explanation

This regex pattern matches strings that contain only letters (both uppercase and lowercase) and spaces. ^ asserts the start of the string, [a-zA-Z] matches any letter, \s matches any whitespace character (in this case, space), + allows for one or more occurrences of the previous characters, and $ asserts the end of the string.

javascript

Example Usage

const regex = /^[a-zA-Z\s]+/; 
const str = 'Hello World'; 
console.log(regex.test(str)); // Output: true
Copy
Test the expression

Similar Regular Expressions