EasyRegex Logo
EasyRegex
Nuevo

Match Only Letters and Spaces in JavaScript

javascript

Expresión Regular

^[a-zA-Z\s]+$
Copiar
¿Tienes Comentarios?

Explicación

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

Ejemplo de Uso

const regex = /^[a-zA-Z\s]+/; 
const str = 'Hello World'; 
console.log(regex.test(str)); // Output: true
Copiar
Prueba la expresión

Expresiones Regulares Similares