du5407 2017-07-08 07:51
浏览 361
已采纳

在PHP中使用正则表达式进行用户名验证

I am trying to validate a USERNAME in PHP using Regular Expression. But I am failed. My pattern is: /[^a-z0-9_]/

Rules:

  • username must start number or small letters
  • username support number, small letters and _
  • the end of username character is not be _
  • 写回答

3条回答 默认 最新

  • doumao8803 2017-07-08 08:04
    关注

    The following pattern will work: ^[a-z0-9][a-z0-9_]*[a-z0-9]$

    • ^[a-z0-9]: first character may not be an underscore
    • [a-z0-9_]*: all the others may be anything...
    • [a-z0-9]$: ...except the last one which can't be an underscore.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突