Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on clarification in comment, try this:</p> <p><strong>Try it out:</strong> <a href="http://jsfiddle.net/fsPgJ/2/" rel="nofollow noreferrer">http://jsfiddle.net/fsPgJ/2/</a></p> <p><strong>EDIT:</strong> Added a <code>keypress</code> event to deal with the user holding down a key.</p> <pre><code>$('input').blur(function() { var val = this.value.toLowerCase(); if(val != "yes" &amp;&amp; val != "no") { this.value = ''; alert( "'Yes' or 'No' is required. \n Please try again."); } }) .keypress(function() { var val = this.value.toLowerCase(); if(val != "yes" &amp;&amp; val != "no") this.value = ''; }) .keyup(function() { var val = this.value.toLowerCase(); if("yes".indexOf(val) != 0 &amp;&amp; "no".indexOf(val) != 0) { this.value = this.value.substr(0,this.value.length - 1); } }); </code></pre> <hr> <p><strong>Original:</strong></p> <p>If there's some reason you're not using a <code>&lt;select&gt;</code> or <code>:radio</code> or something, then you could have jQuery check the value on a <code>.blur()</code> event.</p> <p><strong>Try it out:</strong> <a href="http://jsfiddle.net/fsPgJ/" rel="nofollow noreferrer">http://jsfiddle.net/fsPgJ/</a></p> <pre><code>$('input').blur(function() { var val = this.value.toLowerCase(); if(val != "yes" &amp;&amp; val != "no") { this.value = ''; alert( "'Yes' or 'No' is required. \n Please try again."); } }); </code></pre> <p>This just clears the input if the (case insensitive) value is not "yes" or "no". I also added an <code>alert()</code> to give the user a little feedback as to why the field was cleared. You may want a different feedback approach.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload