各種條件判斷代碼

          //去掉空格
          function Trim(str){
          if(str.charAt(0) == " "){
          ? str = str.slice(1);
          ? str = Trim(str);
          }
          return str;
          }

          //判斷是否是空
          function isEmpty(pObj,errMsg){
          var obj = eval(pObj);
          if( obj == null || Trim(obj.value) == ""){
          ? if (errMsg == null || errMsg =="")
          ?? alert("輸入為空!");
          ? else
          ?? alert(errMsg);
          ? obj.focus();
          ? return false;
          }
          return true;
          }

          //判斷是否是數字
          function isNumber(pObj,errMsg){
          var obj = eval(pObj);
          strRef = "1234567890";
          if(!isEmpty(pObj,errMsg))return false;
          for (i=0;i<obj.value.length;i++) {
          ? tempChar= obj.value.substring(i,i+1);
          ? if (strRef.indexOf(tempChar,0)==-1) {
          ?? if (errMsg == null || errMsg =="")
          ??? alert("數據不符合要求,請檢查");
          ?? else
          ??? alert(errMsg);
          ?? if(obj.type=="text")
          ??? obj.focus();
          ?? return false;
          ? }
          }
          return true;
          }

          //判斷是否是數字,數字可以為負數
          function isNegative(pObj,errMsg){
          var obj = eval(pObj);
          strRef = "1234567890-";
          if(!isEmpty(pObj,errMsg))return false;
          for (i=0;i<obj.value.length;i++) {
          ? tempChar= obj.value.substring(i,i+1);
          ? if (strRef.indexOf(tempChar,0)==-1) {
          ?? if (errMsg == null || errMsg =="")
          ??? alert("數據不符合要求,請檢查");
          ?? else
          ??? alert(errMsg);
          ?? if(obj.type=="text")
          ??? obj.focus();
          ?? return false;
          ? }else{
          ?? if(i>0){
          ??? if(obj.value.substring(i,i+1)=="-"){
          ???? if (errMsg == null || errMsg =="")
          ????? alert("數據不符合要求,請檢查");
          ???? else
          ????? alert(errMsg);??
          ???? if(obj.type=="text")
          ???? obj.focus();
          ???? return false;
          ??? }
          ?? }
          ? }
          }
          return true;
          }

          //判斷是否是錢的形式
          function isMoney(pObj,errMsg){
          ? var obj = eval(pObj);
          ? strRef = "1234567890.";
          ? if(!isEmpty(pObj,errMsg)) return false;
          ??? for (i=0;i<obj.value.length;i++) {
          ???? tempChar= obj.value.substring(i,i+1);
          ???? if (strRef.indexOf(tempChar,0)==-1) {
          ????? if (errMsg == null || errMsg =="")
          ??? alert("數據不符合要求,請檢查");
          ????? else
          ??? alert(errMsg);??
          ??? if(obj.type=="text")
          ??? obj.focus();
          ??? return false;
          ??? }
          ??? else{
          ??? tempLen=obj.value.indexOf(".");
          ??? if(tempLen!=-1){
          ????? strLen=obj.value.substring(tempLen+1,obj.value.length);
          ????? if(strLen.length>2){
          ??????? if (errMsg == null || errMsg =="")
          ??????? alert("數據不符合要求,請檢查");
          ??????? else
          ??????? alert(errMsg);??
          ??????? if(obj.type=="text")
          ????????? obj.focus();
          ????????? return false;
          ?????? }
          ????? }
          ???? }
          ? }
          ? return true;
          }

          function isLeapYear(year)
          {
          if((year%4==0&&year%100!=0)||(year%400==0))
          {
          return true;
          }?
          return false;
          }

          //判斷時間是否正確

          function isDate(checktext){
          var datetime;
          var year,month,day;
          var gone,gtwo;
          if(Trim(checktext.value)!=""){
          datetime=Trim(checktext.value);
          if(datetime.length==10){
          ? year=datetime.substring(0,4);
          ? if(isNaN(year)==true){
          ?? alert("請輸入日期!格式為(yyyy-mm-dd) \n例(2001-01-01)!");
          ?? checktext.focus();
          ?? return false;
          ? }
          ? gone=datetime.substring(4,5);
          ? month=datetime.substring(5,7);
          ? if(isNaN(month)==true){
          ?? alert("請輸入日期!格式為(yyyy-mm-dd) \n例(2001-01-01)!");
          ?? checktext.focus();
          ?? return false;
          ? }
          ? gtwo=datetime.substring(7,8);
          ? day=datetime.substring(8,10);
          ? if(isNaN(day)==true){
          ?? alert("請輸入日期!格式為(yyyy-mm-dd) \n例(2001-01-01)!");
          ?? checktext.focus();
          ?? return false;
          ? }
          ? if((gone=="-")&&(gtwo=="-")){
          ?? if(month<1||month>12) {
          ??? alert("月份必須在01和12之間!");
          ??? checktext.focus();
          ??? return false;
          ??? }
          ?? if(day<1||day>31){
          ??? alert("日期必須在01和31之間!");
          ??? checktext.focus();
          ??? return false;
          ?? }else{
          ??? if(month==2){?
          ???? if(isLeapYear(year)&&day>29){
          ?????? alert("二月份日期必須在01到29之間!");
          ?????? checktext.focus();
          ?????? return false;
          ???? }??????
          ???? if(!isLeapYear(year)&&day>28){
          ?????? alert("二月份日期必須在01到28之間!");
          ?????? checktext.focus();
          ?????? return false;
          ???? }
          ??? }
          ??? if((month==4||month==6||month==9||month==11)&&(day>30)){
          ???? alert("在四,六,九,十一月份 \n日期必須在01到30之間!");
          ???? checktext.focus();
          ???? return false;
          ??? }
          ?? }
          ? }else{
          ?? alert("請輸入日期!格式為(yyyy-mm-dd) \n例(2001-01-01)");
          ?? checktext.focus();
          ?? return false;
          ? }
          }else{
          ? alert("請輸入日期!格式為(yyyy-mm-dd) \n例(2001-01-01)");
          ? checktext.focus();
          ? return false;
          }
          }else{
          return true;
          }
          return true;
          }


          //判斷是否月份正確

          function isYearMonth(checktext){
          ? var datetime;
          ? var year,month,day;
          ? var gone,gtwo;
          ? if(Trim(checktext.value)!=""){
          ??? datetime=Trim(checktext.value);
          ??? if(datetime.length==7){
          ??? year=datetime.substring(0,4);
          ??? if(isNaN(year)==true){
          ???? alert("輸入錯誤!格式為(yyyy-mm) \n例(2001-01)!");
          ???? checktext.focus();
          ???? return false;
          ??? }
          ??? gone=datetime.substring(4,5);
          ??? month=datetime.substring(5,7);
          ??? if(isNaN(month)==true){
          ???? alert("輸入錯誤!格式為(yyyy-mm) \n例(2001-01)!");
          ???? checktext.focus();
          ???? return false;
          ??? }
          ??? if((gone=="-")){
          ????? if(month<1||month>12) {
          ?????? alert("月份必須在01和12之間!");
          ?????? checktext.focus();
          ?????? return false;
          ?????? }
          ??? }
          ??? else{
          ????? alert("輸入錯誤!格式為(yyyy-mm) \n例(2001-01)!");
          ????? checktext.focus();
          ????? return false;??
          ??? }
          ?? }
          ??? else{
          ????? alert("輸入錯誤!格式為(yyyy-mm) \n例(2001-01)!");
          ????? checktext.focus();
          ????? return false;
          ??? }
          }
          ? return true;
          }

          function fucCheckNUM(NUM) {
          ? if (NUM.length!=11)
          ?? return false;
          ????
          ? var i,j,strTemp;
          ? strTemp="0123456789";
          ? if ( NUM.length== 0)
          ?? return false;
          ? if ( NUM.length== undefined||NUM==undefined)
          ?? return false;
          ? for (i=0;i<NUM.length;i++)
          ? {
          ?? j=strTemp.indexOf(NUM.charAt(i));
          ?? if (j==-1)
          ?? {
          ?? //說明有字符不是數字
          ?? return false;
          ?? }
          ? }
          ? //說明是數字
          ? return true;
          }
          ?
          function click () {
          ? //alert ('不許偷看!禁止使用鼠標右鍵!');
          ? window.event.returnValue=false;
          }

          posted on 2006-06-17 09:08 fw 閱讀(486) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           
          主站蜘蛛池模板: 广宁县| 临颍县| 永州市| 疏勒县| 台南县| 札达县| 永定县| 香港 | 南乐县| 萨迦县| 永安市| 廉江市| 永登县| 牙克石市| 太和县| 纳雍县| 和龙市| 南城县| 炎陵县| 安陆市| 虞城县| 开封县| 缙云县| 临城县| 奉贤区| 广西| 易门县| 东阳市| 固始县| 西华县| 衡南县| 保德县| 定日县| 闽清县| 石屏县| 台南县| 安新县| 莱阳市| 西平县| 芒康县| 峡江县|