<input type = "text" id = "textarea" size = "1" maxlength = "1" onblur = "validate()">
<script type = "text/javascript">
function validate() {
var val = document.getElementById('textarea').value;
if (/[^yn]/gi.test(val)) {
alert ('Wrong content! You must enter y or n');
document.getElementById('textarea').value = "";
return false;
}
}
</script>
It is a bad idea to name an HTML field "textarea". And why a textarea if the only valid entry is y or n?
Due to earlier signalling problems there are short-notice castrations in the Guildford area. - Train announcer at Wimbledon Station.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.