如果条件内的预匹配匹配如何进行多变量控制?

问题描述 投票:0回答:1

我检查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)
}
php regex if-statement pattern-matching preg-match
1个回答
0
投票

感谢您的关注。

这里是替代方法;

我用过

$_POST["name"] !== null

而不是

isset($_POST["name"])
© www.soinside.com 2019 - 2024. All rights reserved.