JS uses regular expressions to control users' input of bank card numbers and formatting. js bank cards
// Js Regular Expression for controlling and formatting the user's input bank card number
<Script language = "javascript" type = "text/javascript"> function formatBankNo (BankNo) {if (BankNo. value = "") return; var account = new String (BankNo. value); account = account. substring ();/* 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) {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 ++) {/* You can change the following space to-, and the effect is good */if (I = 4) account = account + ""; /* Add spaces after the fourth digit of the account */if (I = 8) account = account + "";/* Add spaces after the eighth digit of the account */if (I = 12) account = account + "";/* Add a space after the first digit of the account */account = account + accountNumeric. substr (I, 1) }}else {account = "" + account. substring (1, 5) +" "+ Account. substring () +" "+ account. substring () +"-"+ account. substring ();} if (account! = BankNo. value) BankNo. value = account ;}</script>
<input type="text" value="" size="25" onkeyup="formatBankNo(this)" onkeydown="formatBankNo(this)" name="account" id="account">
The above section describes how to use regular expressions to control the user's input and formatting of bank card numbers. I hope this will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!