一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

js 判断是否为数字正则

时间:2010-08-20 编辑:简简单单 来源:一聚教程网

  * 整数的判定
  * @param type
  *  为空  任意整数
  *  '0+' 非负整数
  *  '+'  正整数
  *  '-0' 非正整数
  *  '-'  负整数
  */

 function isint(type){
  var rt = new array();
  if(type=="0+"){
   rt[0] = "^\d+$";
   rt[1] = "应输入非负整数!";
  }else if(type=="+"){
   rt[0] = "^\d*[1-9]\d*$";
   rt[1] = "应输入正整数!";
  }else if(type=="-0"){
   rt[0] = "^((-\d+)|(0+))$";
   rt[1] = "应输入非正整数!";
  }else if(type=="-"){
   rt[0] = "^-\d*[1-9]\d*$";
   rt[1] = "应输入负整数!";
  }else{
   rt[0] = "^-?\d+$";
   rt[1] = "应输入整数值!";
  }
  return rt;
 }

热门栏目