preg 匹配 php a-zA-Z0-9 和空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4469306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
preg match php a-zA-Z0-9 and space
提问by stefanosn
if (preg_match ('/[^a-zA-Z0-9]/i', $getname)) {
i use this preg_match pattern to check if a string in php contains other charachters than a-zA-Z0-9
. i want to add to the pattern the space...i use '/[^a-zA-Z0-9 ]/i'
but is not working ... how should i do it?
我使用这个 preg_match 模式来检查 php 中的字符串是否包含除a-zA-Z0-9
. 我想在模式中添加空间...我使用 '/[^a-zA-Z0-9 ]/i'
但不起作用...我该怎么做?
i want to allow spaces including a-zA-Z0-9
我想允许空格,包括 a-zA-Z0-9
采纳答案by yoda
if (preg_match ('/[a-zA-Z0-9 ]/', $getname)) {
回答by asdasd
preg_match('/^[a-zA-Z0-9 ]+$/', 'string')
回答by Chander Pal
preg_match("/[^A-Za-z'-'_' ']/", 'string')
preg_match("/[^A-Za-z'-'_'']/", 'string')
if you want to use space in your input field then you have to use this ' ' not this ''.
如果你想在你的输入字段中使用空格,那么你必须使用这个''而不是这个''。
mention space between ' '
提及 ' ' 之间的空格