简体   繁体   English

PHP正则表达式名称不以空格开头

[英]php regular expression name not start with space

I need a regular expression for my name which should contain A-Za-Z\\s and not start with space. 我的名字需要一个正则表达式,其中应包含A-Za-Z \\ s,而不以空格开头。

if (preg_match("/[[[:space:]]A-Za-z\s] | [^(A-Za-z\s)]/",$city  )) {
         error
}

but I does not work. 但我不工作。 I need help. 我需要帮助。 thanks 谢谢

preg_match("/^[A-Za-z][A-Za-z\s]*$/", $city)

This breaks down to: 分解为:

  1. Match anything of [A-Za-z] 匹配任何[A-Za-z]
  2. then match anything of [A-Za-z\\s] arbitrarily often. 然后经常任意匹配[A-Za-z\\s]任何内容。

I'd do: 我会做:

if (preg_match("/^[A-Za-z][A-Za-z\s]+$/", $city)) {
    // OK
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM