日期:2014-05-16 浏览次数:20352 次
<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
body {font-size:12px;}
</style>
</head>
<body>
<input id="t" />
<button id="btn">匹配吗?</div>
<script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
$('btn').onclick = function(){
var s = $('t').value;
var re = /^[a-z]\d$/i;
if(re.test(s)){
alert('匹配')
}else{
alert('不匹配')
}
}
</script>
</body>
</html>
------解决方案--------------------
<script>
function f()
{
var regex = /^[a-z]\d$/i
var v = document.getElementById('i').value;
if(regex.test(v)) alert('正确')
else alert('错误')
}
</script>
<input id='i'/>
<input type='button' value='BTN' onclick='f()'/>