开发者

preg_match string must start with alphabetical char

I have a name field and I want to validate, so the first char must be alphabetical of开发者_JS百科 the name and allow spaces and dashes after. I have this so for but it will allow "-" as first char.

preg_match("/^([a-z -])+$/i", $str)

Thanks


Being specific is the better option. But you can also use an assertion:

preg_match("/^(?![- ])([a-z -])+$/i", $str)

The (?!..) can exclude characters from occuring first. You could also use a positive assertion like (?=\w).


preg_match("/^[a-z][a-z -]+$/i", $str)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜