[英]php preg_match not working
This is for my registration page.这是我的注册页面。 I called the regex code in a variable depending on the characters allowed and not allowed inside the textbox.我根据文本框中允许和不允许的字符在变量中调用正则表达式代码。
$txtlastname = $_POST["txtlastname"];
$txtfirstname = $_POST["txtfirstname"];
$txtaddress = $_POST["txtaddress"];
$txtuser = $_POST["txtuser"];
$txtpass = md5 ($_POST["txtpass"]);
$txtcpass = md5 ($_POST["txtcpass"]);
$txtbday = $_POST["txtbday"];
$txtemail = $_POST["txtemail"];
$txtcompany = $_POST["txtcompany"];
$name = "/^[A-Z][a-zA-Z ]+$/";
$emailValidation = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9]+(\.[a-z]{2,4})$/";
$number = "/^[0-9]+$/";
This is my if statement.这是我的 if 语句。 My problem is even if I input the right format inside the textbox and click submit.我的问题是即使我在文本框中输入正确的格式并单击提交。 The "not valid" message is still popping. “无效”消息仍在弹出。
if(!preg_match($name,$txtlastname)){
echo "$txtlastname is not valid";
exit();
}
if(!preg_match($name,$txtfirstname)){
echo "$txtfirstname is not valid";
exit();
}
if(!preg_match($emailValidation,$txtemail)){
echo "This $txtemail is not valid";
exit();
}
Try this - you didn't add the iu
or i
switch.试试这个 - 你没有添加iu
或i
开关。
<?php
$txtlastname = $_POST["txtlastname"];
$txtfirstname = $_POST["txtfirstname"];
$txtaddress = $_POST["txtaddress"];
$txtuser = $_POST["txtuser"];
$txtpass = md5 ($_POST["txtpass"]);
$txtcpass = md5 ($_POST["txtcpass"]);
$txtbday = $_POST["txtbday"];
$txtemail = $_POST["txtemail"];
$txtcompany = $_POST["txtcompany"];
$name = "/^[A-Z][a-zA-Z ]+$/iu";
$emailValidation = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9]+(\.[a-z]{2,4})$/iu";
$number = "/^[0-9]+$/iu";
if(!preg_match($name,$txtlastname)){
echo "$txtlastname is not valid";
exit();
}
if(!preg_match($name,$txtfirstname)){
echo "$txtfirstname is not valid";
exit();
}
if(!preg_match($emailValidation,$txtemail)){
echo "This $txtemail is not valid";
exit();
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.