<script language="javascript"> function trim(s){ return s.replace(/^/s*/,"").replace(//s*$/,""); } function validate(form){ var errStr = ""; var username = trim(form.username.value); var password = trim(form.password.value); var age = trim(form.age.value); var birthday = trim(form.age.value); if(username == "" || username == null){ errStr += "用户名必须输入"; } else if(!/^/w{6,25}$.test(username)){ errStr += "/n用户名必须由字母和数字组成,且长度在6到25之间"; } else if(password == "" || password == null){ errStr += "/n密码必须输入"; } else if(!/^/w(6,25)$.test(password)){ errStr += "/n密码必须由字母和数字组成,且长度在6到25之间"; } else if(age == "" || age == null){ errStr += "/n年龄必须输入"; } else if(!/^[0-1]?[0-9]?[0-9]$/.test(age)){ errStr += "/n您的年龄必须为整数,且必须是一个有效的年龄值"; } else if(birthday == "" || birthday == null){ errStr += "/n生日必须输入"; } else if(!/^19/d/d-[0-1]/d/-[0-3]/d$/.test(birthday)&&!/^20[0-1]/d/-[0-1]-[0-3]/d$/.test(birthday)){ errStr += "/n您的生日格式不正确,格式:yyyy-MM-dd"; } if(errStr== ""){ return true; } else { alert(errStr); return false; } }