我不想使用 preg_match_all ... 因为表单字段仅允许输入数字和字母 ... 只是想知道正确的语法是什么...
没有什么复杂的...只需要知道 preg_match 语句寻找只包含数字和字母的正确语法即可。例如:
preg_match('/^([^.]+)\.([^.]+)\.com$/', $unit)
但那也不能查找数字....
我不想使用 preg_match_all ... 因为表单字段仅允许输入数字和字母 ... 只是想知道正确的语法是什么...
没有什么复杂的...只需要知道 preg_match 语句寻找只包含数字和字母的正确语法即可。例如:
preg_match('/^([^.]+)\.([^.]+)\.com$/', $unit)
但那也不能查找数字....
如果您只想确保一个字符串仅包含字母和数字字符,A-Z、a-z、0-9,则不需要使用正则表达式。
示例来自文档:
<?php
$strings = array('AbCd1zyZ9', 'foo!#$bar');
foreach ($strings as $testcase) {
if (ctype_alnum($testcase)) {
echo "The string $testcase consists of all letters or digits.\n";
} else {
echo "The string $testcase does not consist of all letters or digits.\n";
}
}
?>
上述示例将输出:
The string AbCd1zyZ9 consists of all letters or digits.
The string foo!#$bar does not consist of all letters or digits.
ctype_alnum
是什么意思。+1 - gen_Ericif(preg_match("/[A-Za-z0-9]+/", $content) == TRUE){
} else {
}
如果你想匹配多个条件,那么你需要提供一些代码,我们可以更好地帮助你。
不过,在此期间:
preg_match("/([a-zA-Z0-9])/", $formContent, $result);
print_r($result);
:)
preg_match_all
? - gen_Eric