用javascript+jquery+正则表达式实现用户输入验证

来源:互联网 发布:声音可爱的网络歌手 编辑:程序博客网 时间:2024/05/18 17:44
<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
</head>


<body>


<form action="">
<fieldset>
<legend>个人信息</legend>
<labe for="input1"> 账号:</label>
<input id="input1" /> <!--//把label和文本框关联起来 点任意两个组件都会得打焦点-->
<span></span>
</fieldset>
<fieldset>
<legend>家庭信息</legend>
</fieldset>
<fieldset>
<legend>个人信息</legend>
</fieldset>


</form>
<script src="js/jquery-3.2.1.js" type="text/javascript"></script>
<script>
var reg = /\w{6,}/;


function check() {
var str = $('#input1').val();
if (reg.test(str)) {
$('span').text('ok');
} else {
$('span').text('err');
}
}
$(function(){
$('#input1').blur(function(){
check();
})
})
</script>
</body>


</html>
原创粉丝点击