Created
April 4, 2012 02:28
-
-
Save boyofgreen/2297197 to your computer and use it in GitHub Desktop.
HTML5 Hacks 2.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="myForm"> | |
Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5" oninput= “updateMessage(this)”/> | |
Enter Your Email: <input type="email" name="myEmail" formnovalidate /> | |
<input type="submit" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myForm.quantity. setCustomValidity('looks like your numbers are off a bit, try using a number between one and five') | |
function updateMessage(input){ | |
if(input.value ==""){} | |
input.setCustomValidity(''); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<form name="myForm"> | |
Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5" value="11" /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(document.myForm.quantity.checkValidity() === false){ | |
alert('fail'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(document.myForm.checkValidity() === false){ //myForm is the name of the form element | |
alert('fail'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input {display: block; | |
border: 1px solid #ccc; | |
} | |
:invalid{ | |
border-color: #DB729C; | |
-webkit-box-shadow: 0 0 5px rgba(27, 0, 97, .5); | |
} | |
:required{ | |
border-color: #1BE032; | |
-webkit-box-shadow: 0 0 5px rgba(57, 237, 78, .5); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="myForm" > | |
Enter Your Name: <input type="text" name="myName" placeholder="Enter Your Name" oninput="updateMessage(this)" required> | |
Enter Your Phone Number: <input type="tel" name="myPhone" pattern="\d\d\d-\d\d\d-\d\d\d\d" /> | |
Enter Your Email: <input type="email" name="myEmail" /> | |
<input type="submit" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.myForm.myName.setCustomValidity("To join our list, we at least need to know your name, please enter it here") | |
function updateMessage(input){ | |
if(input.value ==""){} | |
input.setCustomValidity(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment