请帮我写一条正则表达式.谢谢
1.只能匹配 "年 "的正则表达式 例如 2007随便输入四位数字.
------解决方案--------------------
alert(/\d{4}/.test( "2007 "))
------解决方案--------------------
alert(/^\d{4}$/.test( "2007 "))
应该是这样
------解决方案--------------------
reYear =/^19|20\d{2}$/;
------解决方案--------------------
<html>
<script >
function regex()
{
var reYear=/^19|20\d{2}$/;
var str = document.form1.name1.value;
var result = reYear.test(str);
alert(result);
}
</script>
<body>
<form name=form1>
<input type=text name=name1 >
<input type=button onClick= "regex() " value= "test ">
</form>
</body>
</html>
查询谷 - www.chaxungu.com
请帮小弟我写一条正则表达式.多谢
编辑:chaxungu时间:2022-10-02 23:22:02分类:web开发