doulian5857 2018-03-19 12:39
浏览 134
已采纳

用于验证名字和姓氏的PHP正则表达式[重复]

This question already has an answer here:

I am trying to use regex to validate the users first and last name on a form.

Rules

  • Must be alphabetic
  • First letter can either by uppercase or lowercase
  • Followed by all lowercase letters
  • Must be at least 2 letters long and cannot be longer than 15 letters.
  • No spaces.

This is my attempt at the regular expression

!preg_match('/^[a-Z]{1}[a-z]{1,14}$/' 

But I am getting the error:

: preg_match(): Compilation failed: range out of order in character class at offset 4

</div>
  • 写回答

1条回答 默认 最新

  • douliandan7340 2018-03-19 12:42
    关注

    a-Z isn't a valid range, you need to change this to include both uppercase and lowercase ranges.

    change to this: ^[a-zA-Z][a-z]{1,14}$

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探