showing results for - "check if date is valid js"
Fabien
07 Jun 2020
1function isValidDate(dateObject){
2    return new Date(dateObject).toString() !== 'Invalid Date';
3}
Julia
23 Oct 2018
1const isValidDate = function(date) {
2    return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date));
3}
Selene
02 Jan 2017
1var date_regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/;
2if (!(date_regex.test(testDate))) {
3    return false;
4}
Lucia
06 Nov 2019
1function validatedate(inputText,DateFormat)
2{
3// 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
4var invalid = "";
5var dt = "";
6var mn = "";
7var yr = "";
8var k;
9var delm = DateFormat.includes("/") ? "/" : ( DateFormat.includes("-") ? "-" : ( DateFormat.includes(".") ? "." : "" ) ) ;
10var f1 = inputText.split(delm);
11var f2 = DateFormat.split(delm);
12for(k=0;k<=2;k++)
13{ 
14 dt = dt + (f2[parseInt(k)]=="dd" ? f1[parseInt(k)] : "");
15 mn = mn + (f2[parseInt(k)]=="mm" ? f1[parseInt(k)] : "");
16 yr = yr + (f2[parseInt(k)]=="yyyy" ? f1[parseInt(k)] : "");
17}
18var mn_days = "0-31-" + (yr % 4 == 0 ? 29 : 28) + "-31-30-31-30-31-31-30-31-30-31";
19var days = mn_days.split("-");
20if( 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)])) )
21{
22 invalid = "true";
23}
24alert( ( invalid=="true" ? "Invalid Date" : "Valid Date")  );
25}
Hanae
29 Aug 2018
1function isDate(ExpiryDate) { 
2    var objDate,  // date object initialized from the ExpiryDate string 
3        mSeconds, // ExpiryDate in milliseconds 
4        day,      // day 
5        month,    // month 
6        year;     // year 
7    // date length should be 10 characters (no more no less) 
8    if (ExpiryDate.length !== 10) { 
9        return false; 
10    } 
11    // third and sixth character should be '/' 
12    if (ExpiryDate.substring(2, 3) !== '/' || ExpiryDate.substring(5, 6) !== '/') { 
13        return false; 
14    } 
15    // extract month, day and year from the ExpiryDate (expected format is mm/dd/yyyy) 
16    // subtraction will cast variables to integer implicitly (needed 
17    // for !== comparing) 
18    month = ExpiryDate.substring(0, 2) - 1; // because months in JS start from 0 
19    day = ExpiryDate.substring(3, 5) - 0; 
20    year = ExpiryDate.substring(6, 10) - 0; 
21    // test year range 
22    if (year < 1000 || year > 3000) { 
23        return false; 
24    } 
25    // convert ExpiryDate to milliseconds 
26    mSeconds = (new Date(year, month, day)).getTime(); 
27    // initialize Date() object from calculated milliseconds 
28    objDate = new Date(); 
29    objDate.setTime(mSeconds); 
30    // compare input date and parts from Date() object 
31    // if difference exists then date isn't valid 
32    if (objDate.getFullYear() !== year || 
33        objDate.getMonth() !== month || 
34        objDate.getDate() !== day) { 
35        return false; 
36    } 
37    // otherwise return true 
38    return true; 
39}
40
41function checkDate(){ 
42    // define date string to test 
43    var ExpiryDate = document.getElementById(' ExpiryDate').value; 
44    // check date and print message 
45    if (isDate(ExpiryDate)) { 
46        alert('OK'); 
47    } 
48    else { 
49        alert('Invalid date format!'); 
50    } 
51}
52
queries leading to this page
how to check date o object ate formatcheck for a valid date in jscheck if year is valid date javascriptjavascript validation for dd 2fmm 2fyyyy date formatvalid javascript string datevalidate string as date in javascriptjavascript varify the date formatcheck if date formart is valid jsjavascript test for valid datecheck if date string is valid javascriptdate validation with current date in javascriptcheck for valid date in javascriptfrom date to date validation in javascriptvalidate date in javascript html input textcheck if past date and time javascripthow to check date is valid in javascriptjs check if a date is validhow to validate current date in javascriptcheck if the date is valid in javascriptdate validation check in javascriptvalidate datehtml input validation isdatevalidate different types of date with javascriptdate is valid javascriptjavascript validation datevalidate datetime javascriptvalidate date jsjavascript validate date format dd mm yyyy withbooleanhow to check if date is invalidcheck if date is valid date javascripthow to check the date is valid in htmlcheck if date time string is valid date jscheck if string date is valid javascriptjavascript validate date stringjs create date validationvalid date format javascriptcheck valid date in jsvalidatorjs datecheck if date is valid jsjs validate data formatjs check if a string is a valid datejs date is validcheck if valid date string regex javascriptcheck if date valid jsdate is valid date jsjavascript validate date this code use fullvalidate dates in javascripthow to check if date is valid in javascripttest valid date javascriptjs test if valid datehow to check date format validation in javascriptcheck if date format is correct javascripthow to validate date using pattern in javascripthow to create form date to date validation in javascriptdate validator jsjavascript verify datejs check if date string is validget valid date in jsjs check is valid datehow to check if date is valid jsjs to check if date is validcheck a date is valid in javascriptcheck valid date javascripthow to check for date format before converting it javascriptvalidate date inside object javascriptdate field and verification and htmlcheck if js date is validhow to validate year in javascripthow to validate uct date javascriptjavascript validate future datejs how to check if date is validcheck if string is valid date javascriptdate pattern js validatorjs check if valide datedate validateionsdate asking in javascriptvalidate javascript datevalidation date jshow to validate dd mm yyyy format date in javascriptvalidate a date in javascriptjavascript is date validvalid date jsregexp javascript date validation with valide date regex javascriptjs verify a date of birth is validjs test date validnodejs validate datecheck date is valid or not javascriptvalidate date format in javascript mm 2fdd 2fyyyycheck if string is a valid date javascripthow to validate any format in javascriptdate format form validationhow to check for valid date in javascriptassert format date jsvalid date validation in javascriptdate input validation htmlhow to check date format in javascripthow to check date is valid or not in javascripthtml check date formatfrom date and to date validation in jsjavascript if string is valid datejs date validatejavascript validate date this code 22use full 22javascript validate the datejs validate datejavascript check is valid datecheck date is valid javascriptvalidate from date and to date in jsvalidating date format in javascriptvalidate date which is in any format javascriptjs check if invalid datemm dd yyyy input jsjs function to check if date is validjavascript function text date validationjavascript validatordationjavasript valid datehtml date validation check if the data past date in javascripthow to use the date function to validate date in javascripthow to check in js if string value is datevalidator js form for datedate object javascript valid methodnode verify date formatcheck date format in jscheck if date time string is invalid date jsjavascript check if string is datehow to check a date is valid in javascriptdate of birth validation in htmljavascript how to validate valid datecheck the condition if the date value format is not equal to yyyy mm dd in javascriptvalidator js date timebirth date format regex jscheck date valid javascriptvalidate date field in javascripthow to validate date jshow to check if input date format is correct or not using javascriptjavascript check if string is valid dateis valid date jshow to validate date input for teenagers in jsvalidate a date from form nodejsdate validation jsjs validate is string is a datecheck is a date valid javascriptcheck if a string contains a valid year javascriptdob validation in javascriptcheck for invalid date jsjavascript validate if string is a datedate validate in javascriptcheck if a field is in dd 2fmm 2fyyyydate time validation in javascriptcheck format date javascriptvalidator js date format helphow to make a validation date check for javascriptvalid date string javascriptjavascript validate date formatjavascript validation date examplejs valid datehow to validate datea in javascriptnew function with name valid date 28 24month 2c 24day 2c 24year 29date validation in javascriptjavascript check string is valid datevalidate date with javascriptjavascript cheak if date is validhow to check if a date is valid in javascriptvalidate dates javascriptvalid date in javascripthow to check date validation in javascriptdate checking in javascripthow to validate date in javascriptvalidate date format in javascriptjs check valid dateif date format jsjavascript check if date is validdate validation for javascripthow to validate date value without date type in javascriptcheck date format javascriptvalidate datetime in javascriptjs check invalid datehow to check the date is valid or not in javascriptjavascript validate date dd 2fmm 2fyyyyvalidatorjs 2b datevalidate date time jscheck if a string is a valid date javascriptjs check if date is validjs date format checkhow to validate date in javscriptassert format date yyyy mm dd jscheck if date contains time javascriptreg date frontendvalidate if date is valid javascriptjs validate date objectjavascript validate dates libaryjavascript validate datesvalidates that the input string is a valid date formatted dd 2fmm 2fyyyymethod date validator jsjs validate date regexjs validate date stringcheck if there is any valid date in the file such as mm 2fdd 2fyyyy html code type 3d 27date 27 verify datedate dd mm yy if conditionregex for day name validation in javascriptis date valid jshow to validate a date in javascripthow to validate date input in js validate js datejavascript is valid date stringjavascript check if valid date stringjs check if string is a valid datevalidate valid date javascriptvalid date in jsvalidate js date controljs validate date text fieldvalidate date javascript dd 2fmm 2fyyyycheck if the date is valid jshow to check if date is invalid javascriptjs new date 28string 29 tcheck if valid datehow to check if date is valid javascriptdate is valid jsdate check if valid in javascriptdate value is valid javascriptdate validationverify datecheck date validation in javascripthow to check in js if valid date in stringvalidate input date javascriptjavascript validator datedate validation javascript for type datedate validation in jsjavascript cehck if date is validhow to check valid date in javascriptjs date valid checkvalidation for date in javascriptjavascript if new date format is correcthow to validate date in form javascriptjs check date is validjs validate date formatjavascript check date format validnodejs check if date is validwhile creating date format how to check if month is in next yearvulidate datehow to validate date in javascript formis valid date function jsjavascript if valid datejavascript how to validate date date validation in dd mm format using javascripthow to check if string is valid date in javascriptjs check if string is valid datedate javascript validationnew date in javascript validationvalidate current and end date in javascriptvalidate date string javascriptcheck if valid date jsjavascipt check if valid date stringcheck if valid date string javascriptvalidate date format mm 2fdd 2fyyyy javascripthow to validate date field in javascripthow to validate input date jsvalidate year in javascripthow to check valid date javascriptcheck if date format is valid javascriptcheck if date is in the past javascriptcheck valid date format in javascriptjavascript validation date inputdate function validate datecheck if date valid javascriptvalidate date in jshow to check if a date string is valid in jsvalidate month and year javascriptjavascript validate datedate validation using jshow to check if date is valid in jscheck is valid date javascriptpast date validation in javascriptjavascript validate a valid dateverify it is a date jsjscript check if date is validjavascript validate mm validvalidate jscript datevalidate datetime with javascriptjavascript validate if date is validjs how to validate date123 is valid date javascriptjavascript date check for valid datejs check is date validjs valid date stringtypescript 2b check correct date formatvalidation date javascriptjavascript valid date formatjs detect if date is validtypescript from time to time date format validatinjs date validaterdate string validation in javascripthow to check string is valid date or not in javascriptjs validate date objectecheck if date is valid javscriptvalid date format in jsjavascript date how to know if validhow to check if a given string is a valid date in javascriptcheck javascript date validcheck whether string is a valid date in javascriptcheck valid date jsvalidate date format javascriptjavascript date pattern validationvalidate date dd 2fmm 2fyyyy in javascriptverify valid date javascriptcheck if a date is valid javascriptvalidate mm 2fdd 2fyyyy date format javascriptgenerate valid date from date and time jsjavascript check if a date is validjavascript check valid dateverify if date is valid jscheck the data is a valid date in javascriptjs check if string valid datehow to validate a date format in javascriptcheck if date is invalid javascriptjs check if valid datefunction validdate 28 29input day month year validator html and javascriptvalid date validation javascripttest if date is valid javascriptvalidate date html javascriptjavscript validade date timehow to validate date format in javascriptvalidation on date in javascripthow to validate the date in javascripthow to check string format as in mm 2fdd 2fyyyycheck date javascript validationjs is valid datenodejs validate date formathow to check if it 27s a valid date javascriptvalidate date nodejs with new datecheck validate date javascriptvalidate date input in javascriptvalidate date object javascriptvalidate mm 2fyy in javascriptcheck if valid date javascriptvalidate date nodejsjavascript valid date stringjavascript check date is validvalidate datetime format in javascriptinvalid date check in javascriptjs a pattern for testing dates in this format 3a mm 2fdd 2fyyyvalidating date in javascriptjavascript if date is validjavascript check date formatvalidate format jsvalidate form date javascriptvalidate string is date javascriptdate validation javascriptjavascript check valid date stringis date valid javascriptjavascript how to check for valid datejavascript check if date is pastjavascript how to verify date input is correcthow to validate date input in javascriptcheck date validity jsjavascript verify date inputjavascript check pattern day 2fmonth 2fyeardate validatorhow to validate date string in javascriptvalidate date time javascripthow to validate if a date is valid jsjs how to validate date stringjavascript check if valid datevalidate date javascriptdate valid method javascriptchaeck date string is valid in javascriptcheck if date is past date javascriptcheck if valid date object jscheck date validity javascriptexplanation for date javascript validationhow to check if a string is a valid date in javascript how detect an invalid date date instance in javascriptvalidate the date in javascriptvalidate a date javascripthtml date valid date listtypescript year validatorcheck if string is valid date format javascripthow to validate date javascriptvalidate date is valid javascriptfunction validdate 28 29 jsjavascript check if input was the right formatvalidate format date javascriptjavascript date check if validinput date check if is the correct formatjs string is valid datejavascript check date format is validcheck a valid date in javascriptjs validate is correct datedate validation in htmljavascript check if date validcheck if a string is a valid date in java scriptvalidation for date field in javascriptcheck if field is date validationtype the right date javascript validationjs date validationjavascript valid datescheck if past date is valid javascriptvalidate date in javascriptcheck if date entered is valid in javascriptvalidate js date examplejs check date validverify date format javascriptjavascript date validation for past datedate validation for jsvalidate date in htmljavascript date validhow to validate input type 3ddate in javascriptvalidation datecheck if a valid date javascriptext js validate datejavascript check is date validhow to validate date string in nodevalidating dates in javascriptow js validate date formatjs veryify valid date inputshow to add date validation in javascript injs date regex validatedate field verification using javascriptjavascript date validationtypescript date validationyear validation javascriptis valid date javascriptjavascript how to check if date is validcheck if date object is valid javascriptjavascript date is validvalidate date input field only to accept the validated formatcheck date is valid in javascriptjavascript detect invalid datevalide date in jsjs check for valid datetypescript validate date formatjs check date format validjavascript check date format valid es7how to check whether its valid or invalid datemm dd yyyy how to check valid date format javascriptvalidator js isdateform validate of date and time in javascriptjquery match date formathow js validate date formatfunction for date validation in javascriptchecking when a deadline is due in html and javascriptvalidor date time nodeformat validation for date fields javascriptis validate date time dd 2fmm 2fyyyy in javascriptcheck valid date in javascripthow to validate from date and to date in javascriptjavascript verify date string is validjs check that string is datedate format input javascript validationjavascript is valid datejs is date validjavascript check yyyy formatdate is valid date javascriptjavascript check string if datecurrent date validation in javascriptvalid javascript string datetimecheck if date is valid javascriptjs check dateformatis object is valid datevalidating date in javascript discriptionjs to validate datejavascript test valid datejs check if stiring is valid datejavascript past date validationhow to valid date in javascriptcheck is past date is valid in javascriptcheck invalid date javascripthow to check if date is valid in particular format in javascriptjavascript check it date is validcheck if date is valid in jsdate validation in dd format using javascriptvalidate year input javascript regexvalidate the date format using javascriptcheck if valid date jsjs validate full date text fieldjs check to see if date is a certain formatjavascript check formatjavascript valid datecheck if date is valid js