<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2> Javascript </h2>
<!--
<script>
var str = ‘adcdefg‘;//用户名
var reg = /^[a-zA-Z\d]\w{3,11}[a-zA-Z\d]$/;//正则
if(reg.test(str)){
alert(‘验证成功‘);
}else{
alert(‘验证失败‘);
}
</script>
-->
<script>
var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;
//输出 true
console.log(uPattern.test("lAl520_-"));
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/lal520/p/9856513.html
时间: 2024-10-27 11:34:44