Note that there are some explanatory texts on larger screens.

plurals
  1. POssn mask with jquery on android2.3.3
    primarykey
    data
    text
    <p>I am trying to provide a mask to enable user to enter ssn in the format of 999-99-9999. I tried to use the masked input plugin <a href="http://digitalbush.com/projects/masked-input-plugin/" rel="nofollow">from digital bush</a>. This works fine on chrome and safari but doesn't work on android. </p> <p>Problem: When entering the numbers, it is fine until 123- and when I enter the next 2 digits it reverses the sequence. for ex: if I enter 123-45 it displays as 123-54 and this issue continues for each separator. For ex: if I enter 123-45-6789, it displays as 123-56-8974</p> <p>I tried to write my own code as below to handle the keypress and keyup and still get the same issue. Has any one had any success with masking input on android? What is the alternative? </p> <p>Here is the complete html with local links to code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; &lt;title&gt; test ground&lt;/title&gt; &lt;!-- JQuery specific --&gt; &lt;script type="text/javascript" src="libs/jQuery/jQuery.min.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="libs/jQuery/mobile/jquery.mobile.min.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="libs/jQuery/mobile/jquery.mobile.min.css" /&gt; &lt;script src="javascript/jquery.maskedinput-1.3.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;!-- Application specific --&gt; &lt;script type="text/javascript"&gt; $(document).bind('mobileinit',function(){ // $.mobile.page.prototype.options.addBackBtn = true; // $.mobile.page.prototype.options.backBtnText = "Previous"; // $.mobile.page.prototype.options.backBtnTheme = "b"; }); $("[data-role='page']").live("pageshow", function(event) { $("#primaryssn").mask("999-99-9999"); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- ################### PAGE: launchpage ################### --&gt; &lt;div data-role="page" id="launchpage"&gt; &lt;div id="header" data-role="header" data-position="fixed" &gt; &lt;div id="headerlogo" &gt; &lt;/div&gt; &lt;h1 class="appTitle" &gt;My App&lt;/h1&gt; &lt;/div&gt; &lt;div data-role="content" &gt; &lt;div class="content-primary"&gt; &lt;p&gt; Welcome to my app &lt;/p&gt; &lt;br/&gt; &lt;/div&gt; &lt;!-- Primary SSN --&gt; &lt;div data-role="none"&gt; &lt;label name="lblprimaryssn" for="primaryssn" &gt; SSN&lt;/label&gt; &lt;input type="text" name="primaryssn" id="primaryssn" value="" /&gt; &lt;span class="error" id="primaryssnerror"&gt; Please enter your SSN as (999-99-9999) &lt;/span&gt; &lt;/div&gt; &lt;br/&gt; &lt;/div&gt;&lt;!-- /content --&gt; &lt;/div&gt;&lt;!-- /launch page --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is the code I used for masking input based on key stroke on keyup:</p> <pre><code>// _v is value passed in on keyup in this input field // _d indicates if the key is a backspace to delete character var setSSN = function (_v, _d){ var v = $.trim(_v); if ( !_d ){ if ( v.length &lt;= 3 ) { var validformat1=/^\d{1,3}$/ ; if ( validformat1.test(v)) { if ( v.length == 3 ) v = v + '-'; return v; } } else if ( v.length &gt;3 &amp;&amp; v.length &lt;= 6) { var validformat2=/^\d{3}\-\d{0,2}$/ ; if ( validformat2.test(v)) { if ( v.length == 6 ) v = v + '-'; return v; } } else { var validformat3=/^\d{3}\-\d{2}\-\d{0,4}$/ ; if ( validformat3.test(v)) { if ( v.length == 6 ) v = v + '-'; return v; } } v = v.substring(0,v.length-1); return v; } else { if ( 3 == v.length || 6 == v.length ) { v = v.substring(0,v.length-1); } } return v; } </code></pre>
    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.
 

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