如何在php中编辑id代码值

时间:2016-02-04 08:06:21

标签: php

我在邮件中使用下面的代码。但我想更改代码,因此用户输入可以是数字和字母等,因此它可以是任何长度。希望有人可以帮助解决这两项变化。谢谢。

if(isset($_POST['idcode'])) {

    if(strlen($_POST['idcode']) != 8 || !is_numeric($_POST['idcode'])) {

        $error = "input must contain 8 numbers";

    } else {

1 个答案:

答案 0 :(得分:0)

如果你想让它接受所有这一切:

if(isset($_POST['idcode'])) {
// code here

} else {
    $error = "you must set the idcode"; // can be changed
}

但如果你想检查长度为8及以上,请执行以下操作:

if(isset($_POST['idcode'])) {
    if(strlen($_POST['idcode']) >= 8) {
        // code here
    } else {
       $error = "you need to have at least 8 chars"; // can change
    }
} else {
    $error = "you must set the idcode"; // can be changed
}