i am developing a university project in which !preg_match is not working for letters in FORM it takes both Numbers and Letter, do not giver error here is my code:
<?php
$nameErr = $naErr = $cErr = $yErr = "";
$id = $name = $color = $year = "";
if (isset($_POST["submit"])) {
$id = $_POST["id"];
$color = $_POST["name"];
$color = $_POST["color"];
$year = $_POST["year"];
if (!preg_match("[0-9]",$id))
{
$nameErr = "Only number allowed";
}
else if (!preg_match("~/^[a-zA-Z ]*$/~",$name)) {
$cErr = "Only letters allowed";
}
else if (!preg_match("~/^[a-zA-Z ]*$/~",$color)) {
$cErr = "Only letters allowed";
}
else if (!preg_match("[0-9]",$year)) {
$yErr = "Only number allowed";
}
}
?>
Aucun commentaire:
Enregistrer un commentaire