标签:
看到一个关于正则的题,我做了一下,分享一下:
判断字符串是否是这样组成的,第一个必须是字母,后面可以是字母、数字、下划线,总长度为5-20
这是JS部分的代码:
var oBtn=document.getElementById(‘btn‘);
var oT=document.getElementById(‘txt‘);
oBtn.onclick=function(){
var re=/^[a-zA-Z]\w{4,19}$/;
alert(re.test(oT.value));
}
页面:
<input type="text" id="txt">
<input type="button" id="btn" value="判断字符串">
标签:
原文地址:http://www.cnblogs.com/wujidns/p/4174822.html