1

我有一些代码可以获取某人在注册我的应用程序时选择的 URL 并对其进行检查。但我想添加以下限制。

  • 必须至少为 3 个字母
  • 没有大写字母
  • 没有某些词“管理员、支持等……”

这是我到目前为止所拥有的 - 但它现在只寻找特殊字母:

elseif($action == "validate"){

    $option = $_GET["option"];

    $value = $_GET["value"];

    switch($option){

    case "URL":             

$sql = mysql_select_db($value,$connect);
if(preg_match ( "@[^A-Za-z0-9]+@i", $value ) > 0) { $valid = "FALSE";   continue; }

$sql == 1 ?  $valid = "FALSE" : $valid = "TRUE";

}
4

2 回答 2

1
if(preg_match("@^[a-z0-9]{3,25}$@", $value ) && (!preg_match("@admin|support|anything else@",$value))) { 
    //Restrict the word length to 25 characters at max, 3 at least.
    //Do some stuff. The $value meets the requirements as set forth
 ...
}
于 2012-05-22T17:55:16.337 回答
0
elseif($action == "validate"){

    $option = $_GET["option"];

    $value = $_GET["value"];

    switch($option){

    case "URL":             

    $sql = mysql_select_db($value,$connect);
    if(preg_match ( "@[^A-Za-z0-9]+@i", $value ) > 0) { $valid = "FALSE";   continue; }
    if(strlen($value) <= 3) { $valid = "FALSE";   continue; } //less than 3 char
    if(strstr($value, 'admin')) { $valid = "FALSE";   continue; }
      //.. the same for your other words

    $sql == 1 ?  $valid = "FALSE" : $valid = "TRUE";

}
于 2012-05-22T17:55:25.933 回答