我正在尝试验证一个字符串,它必须符合以下规则:
- 允许的字符有:
- 所有Unicode字母[a-z][A-Z]和其他字母,如(á,é,í,ó,ú,ü,ñ等...)
- 所有数字[0-9]
- 这些特殊字符只有(空格,撇号,破折号,句点)
- 该字符串必须至少有4个字母数字字符。空格、撇号、破折号和句点不计入最小长度。
- 该字符串不能以数字、撇号、破折号或句点开头。
- 该字符串必须至少有1个空格在其字符之间。请注意,该字符串已修剪前导和尾随空格,因此永远不会有前导或尾随空格。
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 />";
}
我有困难写下包含至少4个字母和数字且中间有空格的条件。
我想匹配实体的全名,但带有一些宽松的条件。
示例
:
"á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