Horje
validate date Code Example
Is Valid Date ?
const isDateValid = (...val) => !Number.isNaN(new Date(...val).valueOf());

isDateValid("December 17, 1995 03:24:00");
// Result: true
Source: dev.to
javascript validate date
var date_regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/;
if (!(date_regex.test(testDate))) {
    return false;
}
validate date
function validatedate(inputText,DateFormat)
{
// format dd/mm/yyyy or in any order of (dd or mm or yyyy) you can write dd or mm or yyyy in first or second or third position ... or can be slash"/" or dot"." or dash"-" in the dates formats
var invalid = "";
var dt = "";
var mn = "";
var yr = "";
var k;
var delm = DateFormat.includes("/") ? "/" : ( DateFormat.includes("-") ? "-" : ( DateFormat.includes(".") ? "." : "" ) ) ;
var f1 = inputText.split(delm);
var f2 = DateFormat.split(delm);
for(k=0;k<=2;k++)
{ 
 dt = dt + (f2[parseInt(k)]=="dd" ? f1[parseInt(k)] : "");
 mn = mn + (f2[parseInt(k)]=="mm" ? f1[parseInt(k)] : "");
 yr = yr + (f2[parseInt(k)]=="yyyy" ? f1[parseInt(k)] : "");
}
var mn_days = "0-31-" + (yr % 4 == 0 ? 29 : 28) + "-31-30-31-30-31-31-30-31-30-31";
var days = mn_days.split("-");
if( f1.length!=3 || mn.length>2 || dt.length>2 || yr.length!=4 || !(parseInt(mn)>=1 && parseInt(mn)<=12) || !(parseInt(yr)>=parseInt(1900) && parseInt(yr)<=parseInt(2100)) || !(parseInt(dt)>=1 && parseInt(dt)<=parseInt(days[parseInt(mn)])) )
{
 invalid = "true";
}
alert( ( invalid=="true" ? "Invalid Date" : "Valid Date")  );
}




Javascript

Related
jquery alertify Code Example jquery alertify Code Example
how to start v-for on a specific index Code Example how to start v-for on a specific index Code Example
how to pip install jsonlines Code Example how to pip install jsonlines Code Example
jquery.js:10363 Uncaught TypeError: url.indexOf is not a function Code Example jquery.js:10363 Uncaught TypeError: url.indexOf is not a function Code Example
php vscode editor.rulers vetical line delimiter line Code Example php vscode editor.rulers vetical line delimiter line Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7