【发布时间】: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)
}
【问题讨论】:
-
有哪些示例
name和surnamePOST 参数,您的 if 语句似乎失败了? -
抱歉,Else 摔倒了。
-
问题到底是什么?你的代码看起来不错。如果不起作用,请提供导致意外结果的示例数据并解释预期结果是什么。
-
Post方法带来的数据落入else块,虽然它带有模式和其他条件。
-
我用其他数据更新了问题。
标签: php regex if-statement pattern-matching preg-match