HTML5 has ability for form validation. Putting 'required' in input field shows that the field has to be inputted before form submission. Using placholder to get a hint in input field. For email fiedl, you have to enter *@-.-. to be accepted. in url field, I put the pattern to only accept text starting with http:// or https:/. For number field, I put min and max for number range.
Code:
<form action=" " method="post">
<label for="name">Name:</label>
<input type="text" name="name" required placeholder="Name" />
<br />
<label for="email">Email:</label>
<input type="email" name="email" required placeholder="email@example.com" />
<br />
<label for="website">Website:</label>
<input type="url" name="website"
required pattern="https?://.+"
/><br />
<label for="number">Number:</label>
<input type="number" name="number" min="0" max="10" step="2" required placeholder="Even num < 10">
<br />
<label for="range">Range:</label>
<input type="range" name="range" min="0" max="10" step="2" />
<br />
<label for="message">Message:</label>
<textarea name="message" required></textarea>
<br />
<input type="submit" value="Send Message" />
</form>
Demo:
No comments:
Post a Comment