<script>
//检查是否为任意数(实数)
function isNumeric(strNumber) {
var newPar=/^(-|\+)?\d+(\.\d+)?$/
return newPar.test(strNumber);
}
//检查是否为正数
function isUnsignedNumeric(strNumber) {
var newPar=/^\d+(\.\d+)?$/
return newPar.test(strNumber);
}
//检查是否为整数
function isInteger(strInteger) {
var newPar=/^(-|\+)?\d+$/
return newPar.test(strInteger);
}
//检查是否为正整数
function isUnsignedInteger(strInteger) {
var newPar=/^\d+$/
return newPar.test(strInteger);
}
</script>日期格式匹配的正则表达式问题!
http://expert.csdn.net/Expert/topicview.asp?id=1088786
//检查是否为任意数(实数)
function isNumeric(strNumber) {
var newPar=/^(-|\+)?\d+(\.\d+)?$/
return newPar.test(strNumber);
}
//检查是否为正数
function isUnsignedNumeric(strNumber) {
var newPar=/^\d+(\.\d+)?$/
return newPar.test(strNumber);
}
//检查是否为整数
function isInteger(strInteger) {
var newPar=/^(-|\+)?\d+$/
return newPar.test(strInteger);
}
//检查是否为正整数
function isUnsignedInteger(strInteger) {
var newPar=/^\d+$/
return newPar.test(strInteger);
}
</script>日期格式匹配的正则表达式问题!
http://expert.csdn.net/Expert/topicview.asp?id=1088786
验证 时间的JavaScript有吗?格式 12:00
谢谢
function strDateTime(str){
var reg = /^(\d{1,4})-(\d{1,2})-(\d{1,2})\s(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], --r[2],r[3],r[4],r[5]);
if(d.getFullYear()!=r[1])return false;
if(d.getMonth()!=r[2])return false;
if(d.getDate()!=r[3])return false;
if(d.getHours()!=r[4])return false;
if(d.getMinutes()!=r[5])return false;
return true;
}
alert(strDateTime("2000-01-01 12:10"))
</script>
function check(ctime)
{
var re=/(([0-1][0-9])|(2[0-3])):([0-5][0-9])/g;
alert(re.test(ctime));
}
check("12:12")
check("24:23")
check("24:00")
check("17:67")
</script>
function check(ctime)
{
var re=/(([0-1][0-9])|(2[0-3])):([0-5][0-9])/g;
alert(re.test(ctime));
}
check("004:00")
</script>
可爱的微软立刻告诉我 对象不支持 此属性或方法 然后在下句加了黄色标识
var r = str.match(reg);
我的测试代码为以下:(另外你的测试年的函数也报这个问题,是不是我的测试写法有问题?我的IE是6.0 系统2000Server)<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 3</title>
<script language=javascript>
function strDateTime(str){
var reg = /^(\d{1,4})-(\d{1,2})-(\d{1,2})\s(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], --r[2],r[3],r[4],r[5]);
if(d.getFullYear()!=r[1])return false;
if(d.getMonth()!=r[2])return false;
if(d.getDate()!=r[3])return false;
if(d.getHours()!=r[4])return false;
if(d.getMinutes()!=r[5])return false;
return true;
}
alert(strDateTime("2000-01-01 12:10"))
</script>
</head>
<body>
<input name=b alt="日期1" onblur="strDateTime(this)" >
</body>
</html>
如判断日期
<script language=vbscript>
<!--
function myCheckDate(val)
if IsDate(val) then
myCheckDate=true
else
myCheckDate=false
end if
end function
-->
</script>然后
<script language="javascript">
alert(myCheckDate("2002-10-02"))
</script>其他一样处理