I've developed a regex pattern that validates whether a given text is a valid first or last name, returning either true
or false
:
let letters = `a-zA-Z`;
letters += `àáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšž`;
letters += `ÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð`;
const re = new RegExp(`^[$letters][${letters} ,.'’-]+[${letters}.]`, 'u')
return(name.match(re));
Although it currently verifies names beginning with a letter and excluding numerals or most special characters except dot, hyphen, or comma, issues arise with short names like Jo
or Xi
. I understand this is due to the separate blocks in my current setup. How can I adjust the expression to address this issue?
Furthermore, is there a way to concisely condense this without compromising its functionality while still accommodating extended Latin characters?