-2
我试图验证信用卡号码输入至少16位数字。我的代码似乎不工作。我对我的语法不太自信。任何帮助?...谢谢。php strlen验证用户输入至少16位数字
<form name="ccard" action="validate.php" method=post>
CC Type
<select name="cc_type">
<option value="mc">Master Card</option>
<option value="visa">Visa</option>
</select><br>
Creditcard number:
<input type=number name="ccard_num" value="num"><br>
Exp Year:
<input><br>
Exp Month:
<input>
</form>
PHP代码
<?php
$cc_length = $_POST['ccard_num'];
if (strlen($cc_length == 15) {
echo "Valid";
}
elseif (strlen($cc_length != 15) {
echo "Invalid entry";
}
?>
的错误是显而易见的,如果你有错误报告打开PHP会告诉你什么是错的。 –
strlen上的RTM http://php.net/manual/en/function.strlen.php你的答案在那里;-) –
你还应该检查它是否是数字。如果你期望数字。使用'filter_input'或'filter_input_array' –