I'm trying to validate a string that must conform to the following rules:
- Allowed characters are:
- All Unicode letters [a-z][A-Z] and other letters such as (á, é, í, ó, ú, ü, ñ, etc...)
- All numbers [0-9]
- These special characters only (white spaces, apostrophes, dashes, dots)
- The string must have at least 4 alphanumeric characters. White spaces, Apostrophes, Dashes and Dots don't count in the min length.
- The string can not start with a Number, Apostrophes, Dashes or Dots.
- The string must have at least 1 white space between its characters. Note that the string is trimmed for leading and trailing white spaces, so there will never be leading or trailing spaces.
This is how far I got:
if (preg_match("/^[\p{L}\p{M}][\s\p{L}\p{M}-'\.]{4,}$/u", $name, $matches)) {
echo "Match was found: '{$matches[0]}' in '$name'<br />";
}
I'm having difficulty writing the min 4 alphanumeric characters with a space in it condition.
I'm tying to match an entity's full name, but with some relaxed conditions.
Examples
:
"ábc é" --> good
"á bcd" --> good
"abc déf" --> good
"ab cd éf" --> good
"a-1 b4." --> good
"a 123--" --> good
"a 12'34 .-56" --> good
"á" --> bad less than 4 alphanumeric
"ab" --> bad less than 4 alphanumeric
"ábc" --> bad less than 4 alphanumeric
"abcd" --> bad no white space in the string
"1ábc d" --> bad starts with a non letter
"-ábc d" --> bad starts with a non letter
".1ábc d" --> bad starts with a non letter