日期:2014-05-16  浏览次数:20404 次

求解一个与日期有关的正则表达式
+1y -2m +3w -4d
需要验证jQueryUI Datepicker的日期参数格式是否符合要求,其中y,m,w,d分别表示年,月,周,日,4者任意搭配,但不能重复出现,请问各位前辈这个正则该怎么写呢?

------解决方案--------------------
对于页面的时间输入,你可以让用户选择,而不是直接输入
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
日期:<input type="text"  class="input2" name="date1" id="startTime"  
readonly="readonly" onClick="this.value='';fPopCalendar(this,this,this.value);return false;"/><font color="#CCCCCC">点击输入框选择日期</font>
<script>
function getNowDate()
{
   var nn=new Date();
   year1=nn.getYear();
   mon1=nn.getMonth()+1;
   date1=nn.getDate();
   var monstr1;
   var datestr1
   if(mon1<10) 
    monstr1="0"+mon1;
   else
    monstr1=""+mon1;
     
   if(date1<10) 
     datestr1="0"+date1;
   else
     datestr1=""+date1;
   return year1+"-"+monstr1+"-"+datestr1;
}
//last date
function getlastweekDate()
{
   var nn=new Date();
   year1=nn.getYear();
   mon1=nn.getMonth()+1;
   date1=nn.getDate();
   
   var mm=new Date(year1,mon1-1,date1);
   var tmp1=new Date(2000,1,1);
   var tmp2=new Date(2000,1,15);
   var ne=tmp2-tmp1;
   var mm2=new Date();
   mm2.setTime(mm.getTime()-ne);
   
   
   year2=mm2.getYear();
   mon2=mm2.getMonth()+1;
   date2=mm2.getDate();
    
    
     if(mon2<10) 
    monstr2="0"+mon2;
   else
    monstr2=""+mon2;
     
   if(date2<10) 
     datestr2="0"+date2;
   else
     datestr2=""+date2;
 
   
    return year2+"-"+monstr2+"-"+datestr2;
}
 
var gdCtrl = new Object();
var goSelectTag = new Array();
var gcGray = "#808080";
var gcToggle = "#FB8664";
var gcBG = "#e5e6ec";
var previousObject = null;
var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
function fSetDate(iYear, iMonth, iDay){
var VicPopCal = document.getElementById('VicPopCal');
  VicPopCal.style.visibility = "hidden";
  if ((iYear == 0) && (iMonth == 0) && (iDay == 0)){
   gdCtrl.value = "";
  }else{
   iMonth = iMonth + 100 + "";
   iMonth = iMonth.substring(1);
 iDay = iDay + 100 + "";
  iDay = iDay.substring(1);
   if(gdCtrl.tagName == "INPUT"){
      gdCtrl.value = iYear+"-"+iMonth+"-"+iDay;
   }else{
      gdCtrl.innerText = iYear+"-"+iMonth+"-"+iDay;
   }
  }
 
  for (i in goSelectTag)
   goSelectTag[i].style.visibility = "visible";
  goSelectTag.length = 0;
  
  window.returnValue=gdCtrl.value;
  //window.close();
}
function HiddenDiv()
{
var VicPopCal = document.getElementById('VicPopCal');
 var i;
  VicPopCal.style.visibility = "hidden";
  for (i in goSelectTag)
   goSelectTag[i].style.visibility = "visible";
  goSelectTag.length = 0;
}
function fSetSelected(aCell){
var tbSelMonth1 = document.getElementById('tbSelMonth');
var tbSelYear1 = document.getElementById('tbSelYear');
  var iOffset = 0;
  var iYear = parseInt(tbSelYear1.value);
  var iMonth = parseInt(tbSelMonth1.value);
  
  aCell.bgColor = gcBG;
 // with (aCell.children["cellText"]){
  with (aCell.childNodes[0]){
   var iDay = parseInt(innerHTML);
   if (color==gcGray)
  iOffset = (Victor<10)?-1:1;
 iMonth += iOffset;
 if (iMonth<1) {
  iYear--;
  iMonth = 12;
 }else if (iMonth>12){
  iYear++;
  iMonth = 1;
 }
  }
  fSetDate(iYear, iMonth, iDay);
}
function Point(iX, iY){
 this.x = iX;