//js正则实现用户输入银行卡号的控制及格式化
<script language="javascript" type="text/javascript"> function formatBankNo (BankNo){ if (BankNo.value=="") return; var account=new String (BankNo.value); account=account.substring(0,22); if (account.match (".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}")==null){ 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){ var accountNumeric=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++){ if (i==4) account=account + " "; if (i==8) account=account + " "; if (i==12) account=account + " "; account=account + accountNumeric.substr (i,1) } } } else { account=" " + account.substring (1,5) + " " + account.substring (6,10) + " " + account.substring (14,18) + "-" + account.substring(18,25); } if (account !=BankNo.value) BankNo.value=account; } </script>
<input type="text" value="" size="25" onkeyup="formatBankNo(this)" onkeydown="formatBankNo(this)" name="account" id="account">
- 下一篇: 《未转变者》PVP小队生存指南介绍
- 上一篇: 拉马福萨计划任命新的电力沙皇,让非国大措手不及