【问题标题】:How is multiple variable control done for preg match inside of if conditional?如何在 if 条件下对 preg match 进行多变量控制?
【发布时间】:2020-05-09 03:55:56
【问题描述】:

我检查了 post 方法附​​带的输入。但这如果条件代码不起作用。编辑:否则落在他的街区

是 JavaScript

$(".inputonlytext").keypress(function(e) {

    var key = e.keyCode;
    if ((key >= 48 && key <= 57) || (key >= 33 && key <= 47) || (key >= 58 && key <= 64) || (key >= 91 && key <= 96) || (key >= 123 && key <= 127)) {
        e.preventDefault();
    }
    /*if (e.which === 32)
        return false; */
    //var text = $(this).val();
    //$(this).val(text.replace(" ", ""));

});

是输入

<input type="text" name="name" class="form-control inputonlytext" maxlength="50" required="required">
<input type="text" name="surname" class="form-control inputonlytext" maxlength="50" required="required">

是PHP;

if($_POST["name"] !== null && preg_match('/^[a-zA-Z ]+$/', $_POST["name"]) && $_POST["surname"] !== null && preg_match('/^[a-zA-Z ]+$/', $_POST["surname"])){
            //true for my application logic. (think like a reverse)
}else{
            //false for my application logic. (think like a reverse)
}

【问题讨论】:

  • 有哪些示例 namesurname POST 参数,您的 if 语句似乎失败了?
  • 抱歉,Else 摔倒了。
  • 问题到底是什么?你的代码看起来不错。如果不起作用,请提供导致意外结果的示例数据并解释预期结果是什么。
  • Post方法带来的数据落入else块,虽然它带有模式和其他条件。
  • 我用其他数据更新了问题。

标签: php regex if-statement pattern-matching preg-match


【解决方案1】:

感谢您的关注。

这是另一种选择;

我用过

$_POST["name"] !== null

而不是

isset($_POST["name"])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-30
    • 2013-06-27
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多