如何在JAVASCRIPT中验证年龄

来源:百度知道 编辑:UC知道 时间:2024/07/02 13:15:30
我的页面上有年龄一栏、
我想在我的页面前台的javascript中验证、
用户是否输入了、字符串形式的数字。
我该如何去验证呢?
请教各位高手!

var input=document.getElementById('age');
if (/^[0-9]+$/.test(input)){
//输入正确的代码

} else {
//输入错误的代码

}

放日期控件就Ok了嘛
这样方便自己也方便了用户

给你一个日历控件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="zh-cn" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JCalendar 日历控件</title>
<style type="text/css">
#calendar {
border-collapse:collapse;
border:1px solid #06C;
background-