简明现代魔法 -> JavaScript -> JavaScript验证用户输入

JavaScript验证用户输入

2010-06-29

在表单方面,验证用户输入是否合法是个重头戏:

	<body>
		<form action="" method="post">
			<fieldset class="login">
				<legend>Login Information</legend>
				<label for="username" class="hover">Username</label>
				<input type="text" id="username" class="required text"/><br/>
				
				<label for="password" class="hover">Password</label>
			    <input type="password" id="password" class="required text"/>
			</fieldset>
			<fieldset>
				<legend>Personal Information</legend>
				<label for="name">Name</label>
				<input type="text" id="name" class="required text"/><br/>
				
				<label for="email">Email</label>
				<input type="text" id="email" class="required email text"/><br/>
				
				<label for="date">Date</label>
				<input type="text" id="date" class="required date text"/><br/>
				
				<label for="url">Website</label>
				<input type="text" id="url" class="url text" value="http://"/><br/>
				
				<label for="phone">Phone</label>
				<input type="text" id="phone" class="phone text"/><br/>
				
				<label for="age">Over 13?</label>
				<input type="checkbox" id="age" name="age" value="yes"/><br/>
				
				<input type="submit" value="Submit Form