0

我尝试验证该网站的注册表单。不幸的是,无论我在哪里使用了错误的条目,它都会向我显示第一个状态框:

if(isset($_POST['send'])){  
    $freshpw = generate_pw();
    $mdpassword = md5($freshpw);
    $timestamp = mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']);
    $reggebdatum = date("d.m.Y",$timestamp);
    if (empty($_POST['regusername']) ||  check_username($_POST['regusername'])){
        statusbox("Username is given!", 0);
        echo "<div class='sections'>
              </div></div>";
        header("HTTP/1.1 301 Moved Permanently");
        header("refresh:1;url=index.php?act=register");
    }

else if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST['regname']) === 0){
         statusbox("Name can only contains letters spaces and dashes!",0);
        echo "<div class='sections'>
              </div></div>";
        header("HTTP/1.1 301 Moved Permanently");
        header("refresh:1;url=index.php?act=register");
        }


        else if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST['regstreet']) === 0){
                 statusbox("Street can only contains letters spaces and dashes!",0);

        echo "<div class='sections'>
              </div></div>";
        header("HTTP/1.1 301 Moved Permanently");
        header("refresh:1;url=index.php?act=register");
        }
...

如果我测试它并写下某事。故意错误,例如街道或邮编,它总是向我显示名称中的错误:名称只能包含字母空格和破折号

我做某事。错误的??

4

1 回答 1

0

你知道它必须以大写字母开头吗? ^[A-Z]这意味着以大写字母开头:A-Z.

以及为什么preg_match(...) === 0在你应该做!preg_match(...)的时候0或者false在错误的情况下这样做。if(!preg_match())...意味着if(does not match(pattern) or pattern is broken)...所以它是错误处理部分。为了成功测试你做if(preg_match())...

于 2013-07-04T03:26:48.697 回答