Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think there is any such plugin readily available. The problem is a little tricky, because you have to allow the user to type some input before applying your regex. That is, you can't just match against each char as it is typed, unless your regex simply defines a set of characters. </p> <p>To illustrate, if they are entering a payment amount, and you want to allow numbers and decimals on a single-character basis, what prevents them from entering <code>99.99.23.42492</code>? </p> <p>On the other hand, if you supply a complete regex like <code>/\d+\.\d{2}/</code>, then it won't match at all on a single character, you'll have to allow them to type some number of characters before trying to apply the regex and wiping out their input if it doesn't match. That could be frustrating.</p> <p>If you really want to filter the input as they type, then you want to allow a digit for the first character, then digits or a decimal for subsequent characters until the decimal is entered, and then two more digits, and then no more input. It's not a general-purpose filter.</p> <p>For example, here's some code that will do that, but it's very ugly.</p> <pre><code> myInput.keydown(function() { var text = this.val if(!/^\d/.test(text)) { return ''; } else { done = text.match(/^(\d+\.\d\d)/); if (done) { return done[0]; } last_char = text.substr(text.length-1,1); decimal_count = text.replace(/[^\.]/g,'').length; if (decimal_count &lt; 1) { if (!/[\d\.]/.test(last_char)) { return text.substr(0,text.length-1); } } else if (decimal_count == 1 &amp;&amp; last_char == '.') { return text; } else { if (!/[\d]/.test(last_char)) { return text.substr(0,text.length-1); } } return text; } }); </code></pre> <p>And of course, this won't work if they happen to paste in certain values without doing "real" typing.</p> <p>Maybe some other approach would work better for you? Like highlighting the field and indicating to the user if they enter a non-digit, non-decimal, or if they enter more than one decimal, rather than filtering the input itself, because that seems messy.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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