通过js来限制输入框内只能输入数字,并且每输入4位数后,会自动添加一个斜杠,根据自己的需求来修改即可。
<script language="javascript" type="text/javascript"> function www_wuming_ren (BankNo) {//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) 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; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) 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; } function checkBankNo (BankNo) { if (BankNo.value == "") return; if (BankNo.value.match (".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}") == null) { if (BankNo.value.match ("[0-9]{19}") != null) www_wuming_ren (BankNo) }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) } function checkEnterForFindListing(e){ var characterCode; if(e && e.which){ e = e; characterCode = e.which ; } else{ e = event; characterCode = e.keyCode; } if(characterCode == 22){ document.forms[getNetuiTagName("findListingForm")].submit(); return false; } else{ return true ; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) } </script> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> 只能输入数字,并且每输入4位数字会增加一个 - <br /> <input type="text" value="" size="25" onkeyup="www_wuming_ren(this)" onkeydown="www_wuming_ren(this)" name="account" id="account">
本文来自武鸣人网站,转载请注明出处