[英]Input mask for date plus number
有沒有辦法制作日期和數字掩碼? 我需要輸入12/12 / 15-12345甚至更好的121215-12345。 輸入掩碼必須檢查日期是否正確以及在“-”之后僅鍵入5個數字。
> var dateMask = new InputMask(JST_MASK_DATE+[fieldBuilder.literal("-"), fieldBuilder.inputNumbers(1, 5)], "date");
請不要為代碼而怪,我是新來的...嘗試一下..如果可以的話,只要讓我的代碼正常工作,那就太好了。
var date = '121215-13456'; // Here is the string you begin with
var valid = true; // if valid === true, the string is correct
// This will check the structure of the string and store the values in result
var result = /^(\d{2})(\d{2})(\d{2})-\d{5}$/.exec(date);
// If i didn't match the mask
if (result === null)
valid = false;
else
{
var myDate = new Date(2000+parseInt(result[3]), (parseInt(result[2]) - 1), parseInt(result[1]));
// If the date is incorrect
if ((myDate.getMonth() + 1 != parseInt(result[2])) || (myDate.getDate() != parseInt(result[1])) || (myDate.getFullYear() != 2000 + parseInt(result[3])))
valid = false;
}
if (!valid)
{
alert("Invalid");
}
else
{
alert("Valid !");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.