欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS使用正則控制用戶輸入銀行卡號(hào)及格式化

 更新時(shí)間:2017年05月18日 08:44:40   作者:Generon  
本文通過實(shí)例代碼給大家介紹了js使用正則表達(dá)式控制用戶輸入銀行卡號(hào)及格式化的方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

//js正則實(shí)現(xiàn)用戶輸入銀行卡號(hào)的控制及格式化

<script language="javascript" type="text/javascript">
function formatBankNo (BankNo){
  if (BankNo.value == "") return;
  var account = new String (BankNo.value);
  account = account.substring(0,22); /*帳號(hào)的總數(shù), 包括空格在內(nèi) */
  if (account.match (".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}") == null){
    /* 對(duì)照格式 */
    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++){  /* 可將以下空格改為-,效果也不錯(cuò) */
        if (i == 4) account = account + " "; /* 帳號(hào)第四位數(shù)后加空格 */
        if (i == 8) account = account + " "; /* 帳號(hào)第八位數(shù)后加空格 */
        if (i == 12) account = account + " ";/* 帳號(hào)第十二位后數(shù)后加空格 */
        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">

以上所述是小編給大家介紹的JS使用正則控制用戶輸入銀行卡號(hào)及格式化,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論