对于只有字母数字字符我使用这样的东西:
<input type="text" pattern="[a-zA-Z0-9]+" />
Run Code Online (Sandbox Code Playgroud)
当数据到达服务器时,我需要再次验证.所以我做了
preg_match("[a-zA-Z0-9]+", $value);
Run Code Online (Sandbox Code Playgroud)
但PHP说警告:preg_match()[function.preg-match]:未知的修饰符'+'
你不能在html5和PHP中使用相同的表达式吗?
编辑:我有一个JSfiddle显示以下建议不起作用:http: //jsfiddle.net/EY3hc/
我想要实现的是1个正则表达式,我可以在html和preg_match中用作模式.html是由PHP生成的,所以我想有一个地方来维护验证代码.
您需要在表达式中添加分隔符.您还应该匹配行的开头和结尾:
preg_match("/^[a-zA-Z0-9]+$/", $value);
Run Code Online (Sandbox Code Playgroud)
没有^和$,输入就像somewords!@#验证一样.
| 归档时间: |
|
| 查看次数: |
567 次 |
| 最近记录: |