I need to write validation for surname with polish letters.
I wrote something like this:
"^[A-Z][\u0000-\u007F\u0100-\u017F]+([ |-][A-Z][\u0000-\u007F\u0100-\u017F])*$"
where:
[A-Z]: the first letter must be capital[\u0000-\u007F\u0100-\u017F]+: other letters ([ |-][A-Z][\u0000-\u007F\u0100-\u017F])*: space for optional second part of surname with a "-" or spaceEverything is fine, but when I type for example:
"Matt...;'"
I still have a match. How can I "cut" symbols like dots . and quotation marks?
It seems you may use
^[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+(?:\s[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+)?\s[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+(?:-[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+)?$
See the regex demo.
It is based on all Polish alphabet letters regex (that excludes V/v, Q/q and X/x from the ASCII letter range) and will match names that:
Details
^ - start of string[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+ - an uppercase Polish letter and 1+ lowercase ones(?:\s[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+)? - 1 or 0 occurrences of a whitespace and then an uppercase Polish letter and 1+ lowercase ones\s - a single whitespace char[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+ - an uppercase Polish letter and 1+ lowercase ones(?:-[A-PR-UWY-ZĄĆĘŁŃÓŚŹŻ][a-pr-uwy-ząćęłńóśźż]+)? - 1 or 0 occurrences of a hyphen and then an uppercase Polish letter and 1+ lowercase ones$ - end of string.If you plan to support x, q and v in the names, replace a-pr-uwy-z with a-z and A-PR-UWY-Z with A-Z.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With