PHP preg_matches проверки не работает
Для метасимволов я знаю, что они хитры, если они находятся в скобках [], я думал, что они становятся буквальными значениями, а не подстановочными знаками, и вам не нужно выходить с обратной реакцией.
Для $ err_useridpmatch я не понимаю, почему при вводе правильного ввода ошибка все еще отображается, а для $ err_passpmatch, когда я намеренно вводил строку ошибки, включая?, Сообщения об ошибке проверки не было.
<code><?php
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['submit']))):
$userid = trim($_REQUEST['userid']);
$password = trim($_REQUEST['password']);
$err_useridpmatch = '';
$err_passpmatch = '';
if ( !(preg_match('/[^\/.%\\@?]/', $userid)) ) :
$err_useridpmatch = '<div class="error">User id should not have the following characters:/.%\@?</div>';
endif; // pattern doesn't match
if ( !(preg_match('/[A-Za-z0-9.\/]/', $password)) ) :
$err_passpmatch = '<div class="error">Password must only consist of lower or uppercase letters, numbers, full stop or forward slash</div>';
endif; // pattern doesn't match
endif; //form submitted
?>
______________________________________________________________________________
HTML section:
<div id="form-content">
<form name="orderForm" action="<?php echo $_SERVER['PHP_SELF'] ?>" class=""method="post" autocomplete="on">
<table id="formtable">
<tbody>
<br>
<br>
<b><p> Please enter your user id, password and click submit</p></b>
<br>
<tr>
<td class="label"><label for="userid">User ID: </label></td>
<td class="form-input"><input type="text" id="userid" name="userid" value="<?php echo h(@$values['userid']) ?>"/></td>
<td>
<?php if (isset($err_useridpmatch)) { echo $err_useridpmatch; } ?></td>
</tr>
<br>
<tr>
<td class="label"><label for="password">Password: </label></td>
<td class="form-input"><input type="password" id="password" name="password" value="<?php echo h(@$values['password']) ?>"/></td>
<td>
<?php if (isset($err_passwordpmatch)) { echo $err_passwordpmatch; } ?></td>
</tr>
</tbody>
</table>
<p class="required" id="required">Required fields are marked with an asterisk (<abbr class="req" title="required">*</abbr>).</p>
<table id="tablebutton">
<tr>
<td class="buttonfunction"><input type="button" onclick="window.close()" id="cancel" name="cancel" value="Cancel"/></td>
<td class="buttonfunction"><input type="submit" id="submit" name="submit" value="Submit"></td>
</tr>
<!-- <td class="buttonfunction"><input type="submit" onclick="RegisterValidation()" value="Submit">-->
</table>
</form>
</div><!--end form content section-->
<pre>
<?php
if(isset($_POST['submit'])){
print_r($_POST);
}
?>
(1) Идентификатор пользователя не должен содержать следующие символы /.%@?
(2) Пароль должен состоять только из прописных или заглавных букв, цифр, полной остановки или косой черты