File "php_form_validate_name.php"
Full path: E:/sites/Single15/tinmung2007/webroot/THDC-Hai- Ngoai/hocwebchuan_form_validation/php_form_validate_name.php
File size: 746 B
MIME-type:
Charset: utf-8
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>PHP form</title>
</head>
<body>
<form action="" method="post">
Họ tên: <input type="text" name="fullname" value="">
<button type="submit">Gửi</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["fullname"])) {
echo "<span style='color:red;'>Error: Họ tên bắt buộc phải nhập.</span>";
} else {
$fullname = $_POST["fullname"];
if(!preg_match("/^[a-zA-Z ]*$/",$fullname)) {
echo "<span style='color:red;'>Error: Họ tên chỉ chấp nhận chữ và khoảng trắng.</span>";
} else {
echo $fullname;
}
}
}
?>
</body>
</html>