<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
input{
width:400px;
height:40px;
font-size:16px;
border:1px solid #ccc;
}
</style>
</head>
<body>
<h1>银行卡号输入</h1>
<hr>
<span>请输入您的银行卡号:</span>
<br>
<input type="text" name="" id="bank_number" maxlength="23">
<script>
//获取input对象
var input = document.getElementById('bank_number');
//给input绑定事件
input.onkeyup = function(){
//执行替换
input.value = input.value.replace(/\D/g, '');
//执行替换
input.value = input.value.replace(/(\d{4})(?=\d)/g, '$1 ');
}
</script>
</body>
</html>
网友评论