//JS Regular implementation of user input bank card number control and format<script language= "javascript" type= "Text/javascript" >functionFormatbankno (bankno) {if(Bankno.value = = "")return; varAccount =NewString (Bankno.value); Account= Account.substring (0,22);/*total number of accounts, including spaces*/ if(Account.match (". [ 0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7} ") = =NULL){ /*Control Format*/ if(Account.match (". [ 0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}| "+". [0-9] {4}-[0-9]{4}-[0-9]{4}-[0-9]{7}| "+". [0-9] {4}-[0-9]{4}-[0-9]{4}-[0-9]{7}| "+". [0-9] {4}-[0-9]{4}-[0-9]{4}-[0-9]{7} ") = =NULL){ varAccountnumeric = Accountchar = "", I; for(i=0;i<account.length;i++) {Accountchar= Account.substr (i,1); if(!isnan (Accountchar) && (Accountchar! = "")) Accountnumeric = Accountnumeric +Accountchar; } Account= ""; for(i=0;i<accountnumeric.length;i++) {/*The following space can be changed to--the effect is good*/ if(i = = 4) account = account + "";/*Add a space after the fourth digit of the account number*/ if(i = = 8) account = account + "";/*Add a space after the eighth digit of the account number*/ if(i = =) account = account + "";/*Add a space after the 12th digit after the account number*/ Account= account + ACCOUNTNUMERIC.SUBSTR (i,1) } } } Else{ Account= "" + account.substring (1,5) + "" + account.substring (6,10) + "" + account.substring (14,18) + "-" + Account.substri Ng (18,25); } if(Account! = Bankno.value) Bankno.value =Account ;}</script><input type= "text" value= "" size= "onkeyup=" Formatbankno (This) "onkeydown=" Formatbankno (This) " Name= "Account" id= "Account" >
JS Regular implementation of user input bank card number control and format