我需要一些帮助来完成我的表格,我希望某些输入字段只接受字母,一些接受数字等。有人可以帮我举个例子,这样我就可以学习这些?我希望名称只接受字母,电子邮件接受任何但需要“@”符号。希望如果我能在这些方面得到帮助,剩下的事情我可以自己做。
非常感谢
这是我的php表单。
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Daily Dorm News</title>
</script>
<body>
</head>
<body>
<h1>Your Daily Dorm News Post! </h1>
Welcome <?php if ( isset($_GET['name']) and preg_match("/^[A-Za-z0-9]+$/", $_GET['name']) ) {
echo $_GET['name'];
} else {
echo "You entered an invalid name!\n";
}
?><br>
Your email address is: <?php if ( isset($_GET['email']) and preg_match("/.+@.+\..+/i", $_GET['email']) ) {
echo $_GET['email'];
} else {
echo "You didn't enter a proper email address!\n";
}
?><br>
You Posted : <?php echo $_GET["message"]; ?><br>
This event happened :<?php echo $_GET["date"]; ?><br>
<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('EST');
// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');
?>
</script>
</body>
</html>
这是我的 HTML
<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="index.css" />
<meta name="viewport" content="width=device-width" />
<title>Daily Dorm News</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<body>
<div id="dorm"> <u>Daily Dorm News</u> <br> The best place to get your latest Dorm news </div>
<form action="posting_wall.php" method="get">
<div id="container">
Username:<input type="text" name="name" pattern="[A-Za-z0-9]{3,15}" title="Letters and numbers only, length 3 to 15" required autofocus><br>
E-mail: <input type="email" name="email"maxlength="20" required><br>
<div class='message'>
Post: <br>
<textarea rows="10" cols="50" name='message' id='message' pattern=".{3,}" title="3 characters minimum" maxlength="150" required></textarea>
</div>
Date this event took place: <input type="text" name='date' id="datepicker" required> <br>
</div>
<input type="submit">
<input type="reset" value="Reset">
</form>
</body>
</html>