我怎样才能只在单词中允许单个连字符和单个空格,而不是在单词的开头或结尾?
if(!preg_match('/^[a-zA-Z0-9\-\s]+$/', $pg_tag))
{
$error = true;
echo '<error elementid="pg_tag" message="TAGS - only alphanumbers and hyphens are allowed."/>';
}
我不想接受以下这些输入
---stack---over---flow---
stack-over-flow- stack-over-flow2
stack over flow
但只有这些是可以接受的,
stack-over-flow stack-over-flow2 stack-over-flow3
stack over flow
stacoverflow
谢谢。