问题是如何只允许输入产品代码白名单中的内容。
类似于黑名单,但是黑名单不允许您仅输入黑名单中的单词。
但是我只想输入白名单中的产品代码并阻止其他单词输入。
const whitelist = ["AAAB","BBBBBBC","XXXXXXXXXXY","TTA"]
我从数据库中获得产品代码,它们的结尾长度不同。
"AAAB" ending is 7 digit long then product code is like "AAAB0000001", "AAAB0000002"
"BBBBBC" ending is 9 digit long then product code is like "BBBBBC000000001", "BBBBBC000000002"
https://codepen.io/VeltixOfficial/pen/joKdxQ
我的PHP代码:
$data = $pdo->query("SELECT PRODUCT_CODE AS code FROM test")->fetchAll(PDO::FETCH_OBJ);
echo "<pre>";
foreach ($data as $obj) {
echo $obj->code;
$stmt = $pdo->prepare("SELECT ENDING AS ec FROM test WHERE PRODUCT_CODE = :code");
$stmt -> bindParam(':code', $obj->code);
if ($stmt->execute()) {
if ($fetch = $stmt->fetchAll(PDO::FETCH_OBJ)) {
foreach ($fetch as $key) {
echo "<pre>";
echo $key->ec;
echo "</pre>";
}
}
}
}
echo "</pre>";
白名单(产品代码(产品代码的末位数是生产多少个产品)):
AAAB0001, BBBA01, AAC00001, AX001
预期(文本区域):
我只能在白名单的哪个区域键入那些产品代码。
AAAB0001, AAAB0002, AAAB0003, BBBA01, BBBA02, AAC00001, AAC00002, AAC00003, AX001, AX002, AX003, AX004, AAX05..