如何在php中标记字符超出某个范围的数据


how to flag data that has characters outside some range in php

我正在构建一个简单的验证系统,如果字符串的字符超出了可接受的范围,该系统就会对其进行标记。我希望使用一些模式匹配函数来实现这一点,比如。。。

// if data contains anything that is not [A-Z][a-z] or [0-9] the function returns false or an exception
preg_flag_bad_data("[A-Z][a-z][0-9]",$data)

preg_match将为您完成

preg_match("/^[A-Za-z0-9]*$/", $subject);

无需创建新功能