即使我輸入的電話號碼無效,我的正則表達式也會驗證它並顯示有效的消息。任何想法最新怎麼了?正則表達式驗證不起作用(電話和姓名)
<form action="<?php $PHP_SELF; ?>" method="POST">
Name (First Middlie Last) : <input type="text" name="name" value=""><br />
Telephone Number : <input type="text" name="phone" value=""><br />
<input type="submit">
</form>
<?php } else {
extract($_REQUEST);
$phoneDashes = preg_replace("/\D/","", $phone);
$nameRegex = $_POST['name'];
if(preg_match("/(\d{3})(\d{3})(\d{4})/", $phoneDashes,$matches)) {
echo "Valid phone number <br />";
}
else {
echo "Not a valid phone number <br />";
}
preg_match("/(^[\-a-z]+)\s([\-a-z])\s([\-a-z]+)$/i", $nameRegex,$names);
echo "Your name: $names[3], $names[2] $names[1] <br />";
echo "Your phone Number: $matches[1]-$matches[2]-$matches[3] <br />";
}
?>
你在'if'語句中使用了什麼字符串? – VMAtm
電話號碼字符串?問題在哪裏? – harry
不,你用什麼值得到錯誤的結果? – VMAtm