dongyingjiu0669 2012-11-08 16:45
浏览 130
已采纳

preg_match永远不会通过

My account creation script's name input is validated with a preg_match as the field is only allowed to have either Latin or Cyrillic characters (in other words, it cannot have both), however, no matter what the name field contains, the preg_match condition is never satisfied. So far I've tried three possible variations of the code:

if (!(preg_match('/^[a-z]$/i',$_POST['name']) || preg_match('/^[а-я]$/i',$_POST['name']))) back('The message');

if (!preg_match('/^[a-z]$/i',$_POST['name']) &&  !preg_match('/^[а-я]$/i',$_POST['name'])) back('The message');

and one that attempts to stuff both the preg matches into one.

Could anyone please help me out in fixing this issue?

  • 写回答

4条回答 默认 最新

  • douzhuo6931 2012-11-08 16:50
    关注

    The problem is that you are limiting the name to exactly one character:

    /^[a-z]$/i
    

    Change it to:

    /^[a-z]+$/i
    

    and

    /^[а-я]+$/i
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM