It looks like my solution can easily handle that
```
^(?=([A-ZÀ-ÝŐŰẞŒ]|([a-zß-ÿőűœ][ '])))(?=(?![a-zß-ÿőűœ]+[A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[A-ZÀ-ÝŐŰẞŒ][A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[- '][- ']))[A-ZÀ-ÝŐŰẞŒß-ÿőűœa-z- ']{2,}([a-zß-ÿőűœ]|(, Jr.))$
```
<!-- begin snippet: js hide: false console: true babel: false babelPresetReact: false babelPresetTS: false -->
<!-- language: lang-js -->
function myFunction() {
const pattern = "^(?=([A-ZÀ-ÝŐŰẞŒ]|([a-zß-ÿőűœ][ '])))(?=(?![a-zß-ÿőűœ]+[A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[A-ZÀ-ÝŐŰẞŒ][A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[- '][- ']))[A-ZÀ-ÝŐŰẞŒß-ÿőűœa-z- ']{2,}([a-zß-ÿőűœ]|(, Jr.))$";
var regex = new RegExp(pattern, 'gm');
var a = document.getElementById("myText");
var b = a.value;
var c = regex.test(b);
var d = document.getElementById("result") ;
d.innerHTML = "Result:";
if(b != ""){
if(c){
d.innerHTML += " passed";
}
else{
d.innerHTML += " failed";
}
}
else{
return
}
}
<!-- language: lang-css -->
input[type=text] {
width: 99%;
padding: 4px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #04AA6D;
color: white;
padding: 4px;
border: none;
cursor: pointer;
width: 25%;
}
button:hover {
opacity: 0.8;
}
<!-- language: lang-html -->
<h2>Name Validation Regex Pattern </h2>
<div class="container">
<label for="name"><b>Name</b></label>
<input type="text" id="myText" placeholder="Enter Your Name" name="name" value="">
</div>
<div class="container">
<button onclick="myFunction()">Try it</button>
<p id="result"> Result: </p>
</div>
</div>
<!-- end snippet -->
Try this regex
```
^[^- '](?=(?![A-Z]?[A-Z]))(?=(?![a-z]+[A-Z]))(?=(?!.*[A-Z][A-Z]))(?=(?!.*[- '][- '.]))(?=(?!.*[.][-'.]))[A-Za-z- '.]{2,}$
```
[Demo][1]
[1]: https://regex101.com/r/nMStwW/1
Edited Oct 13, 2024
My latest solution for int names:
```
^(?=([A-ZÀ-ÝŐŰẞŒ]|([a-zß-ÿőűœ][ '])))(?=(?![a-zß-ÿőűœ]+[A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[A-ZÀ-ÝŐŰẞŒ][A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[- '][- ']))[A-ZÀ-ÝŐŰẞŒß-ÿőűœa-z- ']{2,}([a-zß-ÿőűœ]|(, Jr.))$
```
<!-- begin snippet: js hide: false console: true babel: false babelPresetReact: false babelPresetTS: false -->
<!-- language: lang-js -->
function myFunction() {
const pattern = "^(?=([A-ZÀ-ÝŐŰẞŒ]|([a-zß-ÿőűœ][ '])))(?=(?![a-zß-ÿőűœ]+[A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[A-ZÀ-ÝŐŰẞŒ][A-ZÀ-ÝŐŰẞŒ]))(?=(?!.*[- '][- ']))[A-ZÀ-ÝŐŰẞŒß-ÿőűœa-z- ']{2,}([a-zß-ÿőűœ]|(, Jr.))$";
var regex = new RegExp(pattern, 'gm');
var a = document.getElementById("myText");
var b = a.value;
var c = regex.test(b);
var d = document.getElementById("result") ;
d.innerHTML = "Result:";
if(b != ""){
if(c){
d.innerHTML += " passed";
}
else{
d.innerHTML += " failed";
}
}
else{
return
}
}
<!-- language: lang-css -->
input[type=text] {
width: 99%;
padding: 4px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #04AA6D;
color: white;
padding: 4px;
border: none;
cursor: pointer;
width: 25%;
}
button:hover {
opacity: 0.8;
}
<!-- language: lang-html -->
<h2>Name Validation Regex Pattern </h2>
<div class="container">
<label for="name"><b>Name</b></label>
<input type="text" id="myText" placeholder="Enter Your Name" name="name" value="">
</div>
<div class="container">
<button onclick="myFunction()">Try it</button>
<p id="result"> Result: </p>
</div>
</div>
<!-- end snippet -->