js 正则表达式小结

时间:2011-11-10 杂志管理

1  数字:前4位是年份[2000-2099],后三位是数字,如2018001

   patn1=/^20[0-9][0-9]\d{3}$/;

    
    if(trim(pe)==""){ 
     alert("请输入期数!");   
    }else if(!patn1.test(pe)){
     alert("请输入合法的期数!");
     return false;
    }

2 验证图片格式只能为 png bmp jpg gif   这四种格式

  var patn = /\.png$|\.bmp$|\.jpg$|\.gif$/; 

  if(!patn.test(coverUrl)){
     alert("图片格式不正确!");
              return false;
    }

猜你喜欢

转载自helloworlda.iteye.com/blog/1249538
今日推荐