Jquery limit text in text field copy safe
<p>Here is a mind Boggling question i am having trouble with. I have a text field. This text field needs to accommodate U.S mobile numbers with 4 formats </p>

<ol>
<li>XXX-XXX-XXXX </li>
<li>XXXXXXXXXX</li>
<li>X-XXX-XXX-XXXX</li>
<li>XXXXXXXXXXX</li>
</ol>

<p>When the last character is entered it needs to do a check via ajax which i have no problem with. </p>

<p>I need to check if the textbox has the full mobile number in when typing, copying and pasting, deleting and every possible way to put numbers in that field. </p>

<p>i tried checking it with $("#id").keyup but that doesn't work when you paste something. </p>

<p>is there a way to check either via interval or something else if there is 10 or eleven characters in that field regardless of how it got there? [edit]</p>

<p>Here is a solution i found</p>

<pre><code>var checkMsisdnInterval = window.setInterval( function () {
    var msisdn = getdigits($("#newSessionMsisdn").val());

    if(msisdn.length == 10 &amp;&amp; !checked) {   
        doPreCheck(msisdn);
        checked = true;
    } else if(checked == true) {
        //do something here
    } else {
        //do something else 
    }
}, (1000 * 60 * 0.1));

$("#newSessionMsisdn").keyup(function(){
    checked = false;
});

function getdigits (s) {
   return s.replace (/[^\d]/g, "");
}
</code></pre>

<p>it works like a bomb. Thanks for all the replies</p>
