Validating the Name entered by a User contain the following check
So, the regular expression for this is
^[A-Z][a-z]*(\.?\s?[A-Z][a-z]*)+$
This means
^
-> Should start with
[A-Z]
-> the first letter should be capital case
[a-z]*
-> the leading letters should be small case (Optional and not applicable for Initials. Ex : J. Doe)
(\.?\s?[A-Z][a-z]*)+
-> A dot (.) and/or a space (" "), then a capital case and small cases. The last + indicates that this part can repeat many times and at least one time it should be there.
$
end. No further words will be there
Example matching : J. Doe , John Doe, John Doe Doe, John D Doe.
Example in JavaScript
var name = "John Doe";
var noname = "123Abc";
console.log(/^[A-Z][a-z]*(\.?\s?[A-Z][a-z]*)+$/.test(name)); // true
console.log(/^[A-Z][a-z]*(\.?\s?[A-Z][a-z]*)+$/.test(noname)); // false