-2

我需要执行一个 if 语句来过滤一些字符串。

如果字符串包含0-9, whitespace, commas or brackets我想让它们通过。所以这个字符串应该通过 -

[[1,1],[2,3]]

但是,如果字符串是,或者说,或者Hello World因为它们包含的字符不是[Hello World][1, $]0-9, whitespace, commas or brackets

那么最好的方法是什么?

4

1 回答 1

3
if (preg_match("/[^\d\s,\[\]]/", $string)) {
    //Invalid
}
于 2012-08-21T12:31:00.633 回答