带有HTML5空格的名称的正则表达式[重复]

This question already has an answer here:

I tried below pattern for Name field in HTML5, but everytime I am getting error :- "Please match the requested format"

Apart from above pattern, I also gave different pattern like :- a) pattern="/^[A-Za-z\s]+$/" b) pattern="/^[A-Za-z]\s[A-Za-z]+$/"

All the three pattern are not working. What I want is simple Firstname Lastname like "Harry Potter". Please advice.

Thanks in advance.

</div>

You need to remove leading and trailing slashes from your pattern because in JavaScript they're indicate that string is actually a regular expression, but in html attribute it is already known to be a regular expression.

Pattern itself will depend on what kind of names you want to accept, your expression will not accept non-latin names, but there is a lot of people with such names. Basically if you want to check for existence of at least 2 words (since name can contain more then 2 words). For example you can use this pattern="\D\S+(\s+\D\S+)+" that will check for existence for at least 2 words separated by whitespace and each word should not start with a digit.