<script>
//42........x
//42 112620001126171 x
//42\d{15}(\d|x)
var str = "42110619881024307x";
var res = /^42\d{15}[\dx]$/;
console.log(res.test(str))
</script>
<input type="text" placeholder="请输入密码" id="app">
<script>
/*
密码
必须包含大写小写至少6位数字且以大写字母开头
*/
var reg = /^[A-Z]+[a-z]+\d{6,}$/
$("#app").keyup(function(event){
if(event.keyCode ==13){
var value = $(this).val();
console.log(reg.test(value))
}
})
</script>
指定匹配位置
<script>
/*
*/
var str = "1fiddewew"
var reg = /^[0-9]+/
console.log(reg.test(str))
console.log(/\d+$/.test(str))
var str = " hello ";
var reg = /(^\s+)|(\s+$)/g
console.log(str.trim())
console.log()
</script>
非
<script>
var str = "abc123";
var reg = /[^abc]/g;
console.log(str.replace(reg,"*"))
var test = "?@hello123-";
/*123*/
var reg = /[^\d]/g;
console.log(test.replace(reg,"*"))
</script>