一:验证日期

1:日期必须满足yyyy-MM-dd格式

2:日期必须是合法的日期,如2016-02-30就是不存在

1 //验证就诊日期
2         function checkVisitDate(date){
3             var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
4             if(reg.test(date)){ //如果满足正则表达式,则判断是否是合法的日期
5                 return new Date(date).getDate() == date.substring(date.length-2);
6             }
7             return false;
8         }

 

二:验证年龄

1:年龄必须大于0

2:1到3位的数字

1 //验证年龄
2         function checkAge(age){
3             var reg = /^\d{1,3}$/; //大于0的1到3位数字
4             if(age && age > 0 && !reg.test(age)){
5                 alert("请输入正确的年龄!");
6             }
7         }

 

三:验证身份证号

1:身份证号有15位或者18位

2:15位全为数字,18位最后一位可以为X或者x

1 //验证身份证号
2         function checkIdNo(idNo){
3             var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
4             if(idNo && !reg.test(idNo)){
5                 alert('请输入正确的身份证号!');
6             }
7         }

 

相关文章:

  • 2022-01-14
  • 2021-05-18
  • 2021-12-22
  • 2021-05-15
  • 2022-01-11
  • 2021-08-02
  • 2021-10-19
  • 2021-11-13
猜你喜欢
  • 2021-07-05
  • 2021-09-15
  • 2022-01-14
  • 2022-01-10
  • 2022-12-23
  • 2021-11-17
  • 2021-12-31
相关资源
相似解决方案