lena lena - 2 months ago 16
jQuery Question

How to check if a string containing space is alphabet or not in jquery?

I have written a code in jquery to check if a word is alphabet or not. But I want to write the code for checking a string which contains space also.

var letters = /^[A-Za-z]+$/;

var msg = "Enter a valid name !!!";
document.getElementById("resp").innerHTML = msg;


for the input field :

<input type="text" name="name" id="namee" placeholder="Full Name" pattern="[a-zA-Z]+" required>

When i am inputing a name having two words, the message valid name is showing becos the space character is read as a invalid character. Can anyone suggest how to correct this ?


You may use the regex

/^[A-Za-z ]+$/