dongyue9864 2014-01-06 16:00
浏览 92
已采纳

php正则表达式不允许字符串中的DOT

Here is my code at the moment, allowing ONLY a-z and 0-9. If I wanted a similar regExp that will NOT allow any string containing a dot (.) how would I have to modify it?

if ( preg_match('/^[a-z0-9_]+$/',$myExtraField) == false ) {

This is inside a symfony2 form class, not sure whether the regExp is the same as flat PHP hence I included my present regExp... never had the time to dive into regExp and hardly ever use it.

  • 写回答

4条回答

  • duanchun2349 2014-01-06 16:03
    关注

    The simplest check you could do would be

    strpos($myExtraField, ".") === false
    

    If you really wanted to use a regex, you could invert preg_match("/\./") or just do a check like preg_match("/^[^.]*$/")

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器