douduikai0562 2013-04-28 16:22
浏览 25
已采纳

按Enter键时出现preg_match错误消息

I have the following code in php, which enables field "news" to get only the characters a-z and numbers 0-9 and space. How can I modify it, so except a-z, 0-9 and space to get "enter"? because when I type enter I get the error message "News field, must only contains a-z, 0-9 characters and spaces"

if( preg_match("&[^a-zA-Z0-9 ]&",$_POST['news']) ){
    $errors[]='<font color="#963">News field, must only contains a-z, 0-9 characters and spaces</font>';
} preg_replace("&[^a-zA-Z0-9 ]&","",$_POST['news']);    
  • 写回答

1条回答 默认 最新

  • dqg17080 2013-04-28 16:28
    关注

    Try this:

    &[^a-zA-Z0-9\s]&
    

    the \s should find any type of whitespace, including newlines and spaces. if you only want spaces and newlines (not tabs or other whitespace) you can do &[^a-zA-Z0-9 ]& instead.

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

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义