Skip to content

Instantly share code, notes, and snippets.

@mulderu
Created January 12, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mulderu/c392328699e9acae318f3ca954362baf to your computer and use it in GitHub Desktop.
Save mulderu/c392328699e9acae318f3ca954362baf to your computer and use it in GitHub Desktop.
html5 form validation and user message
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>HTML5 Form Validation Ex</title>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<form onsubmit="return false;">
<label for="choose">Would you prefer a banana or a cherry?</label>
<input id="choose" name="i_like" required pattern="banana|cherry" >
<button>Submitx</button>
</form>
<script>
$(document).ready(myInit);
function myInit() {
$('#choose').blur(function(e) {
setTimeout(function() {
$('#choose')[0].setCustomValidity('hello mulder');
$('#choose')[0].reportValidity();
}, 1);
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment