Full version: jsB@nk » Form » Validation » JavaScript Proper Social Security Number Validation
URL: https://www.javascriptbank.com/javascript-proper-social-security-number-validation.html
One more JavaScript code example to accept numeric characters. But this JavaScript will work in the different manner, it only allows a set number of characters to be entered into a text field and then focus on the next element, the users can still enter other characters but the form will be disabled until they entered right. Easy to implement and edit as you want.
Full version: jsB@nk » Form » Validation » JavaScript Proper Social Security Number Validation
URL: https://www.javascriptbank.com/javascript-proper-social-security-number-validation.html
<script type="text/javascript">// Created by: Mr. J | http://www.huntingground.net// This script downloaded from www.JavaScriptBank.comfunction advance2(currentField,nextField,limit) { if(nextField!="rset"&&document.myForm2[currentField].value.length == limit){ document.myForm2[nextField].select(); } else { if (document.myForm2[currentField].value.length == limit) { document.myForm2[currentField].maxLength=limit document.myForm2[nextField].select() document.myForm2[nextField].disabled=false document.myForm2[currentField].blur() document.myForm2[nextField].style.backgroundColor="#EFCCA4" } }}</script>
<p>This form is formatted for a social security number (XXX-XX-XXXX).</p><form name="myForm2" onreset="this.rset.disabled='true'; this.rset.style.backgroundColor=''"><input type="text" name="t1" size="6" onclick="select()" onKeyUp="advance2('t1','t2',3)"><input type="text" name="t2" size="6" onclick="select()" onKeyUp="advance2('t2','t3',2)"><input type="text" name="t3" size="6" onclick="select()" onKeyUp="advance2('t3','rset',4)"><input type="reset" name="rset" onclick="this.blur()" disabled></form><div style="text-align: left; width: 70%;"><p>The limit for each individual field is passed to the function by the appropriate input event, as shown in the form using the format: <code>onKeyUp="advance2('currentField','nextField',limit)</code>"</p></div>