javascript validate date

Solutions on MaxInterview for javascript validate date by the best coders in the world

showing results for - "javascript validate date"
Luka
12 Feb 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}
Felipe
15 Jan 2021
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
Matteo
07 Mar 2018
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}
queries leading to this page
check date validity javascriptfrom date to date validation in javascriptcheck if date formart is valid jswhile creating date format how to check if month is in next yearhow to check if date is valid in particular format in javascripthow to check if a date is valid in javascripttypescript from time to time date format validatinjavascript check if date validjs validate is correct datevalid date validation in javascriptjavascript is valid datehow to validate date in form javascriptjavascript date is validhow js validate date formatvalidate js date controljs validate data formathow to check if date is valid jsdate validatorvalidate datetime with javascriptvalidate date time jsjs veryify valid date inputsjs detect if date is validvalidate year input javascript regexdate validation javascriptjavascipt check if valid date stringcheck date validity jsvalidator js form for datecheck if field is date validationdate field and verification and htmlcheck if valid date javascriptcheck valid date in javascriptcheck valid date javascriptjavascript verify date inputcheck a date is valid in javascriptjavascript how to verify date input is correctjavascript date check for valid datevalidate date javascript dd 2fmm 2fyyyyhow to check if date is valid in jshow to validate year in javascriptjavascript verify datereg date frontendcheck date is valid in javascriptjavascript check date format valid es7check date validation in javascriptjs date valid checkcheck if a string is a valid date javascriptjavascript check if date is validvalidate date format javascriptinput day month year validator html and javascriptvalidation on date in javascriptdate is valid date jsvalidating date in javascriptmm dd yyyy how to check valid date format javascriptcheck if js date is validcheck if past date is valid javascriptjavascript test valid datejs check if stiring is valid datehow to validate from date and to date in javascriptjavascript function text date validationdate time validation in javascriptjs check date format validcheck date format javascriptcheck is past date is valid in javascriptvalidation for date in javascriptdate value is valid javascripthtml code type 3d 27date 27 verify datejavascript validate datesvalidation date jsvalidate datetime format in javascriptvalidate date html javascriptvalidator js date timejavascript check if valid date stringjavascript validate the datehow to check if a date string is valid in jsjs check for valid datedate valid method javascriptvalidate date in jshow to validate date value without date type in javascriptvalidate date inside object javascripthow to validate a date in javascriptdate validation for javascriptvalidate the date in javascriptjs verify a date of birth is validhow to use the date function to validate date in javascriptjs check is date validdate validation jsjs check date validjscript check if date is validjavascript check if string is valid dateget valid date in jstypescript 2b check correct date formathow to validate date jsjs check valid datejavascript check valid date stringvalidator js isdatejs test date validvalidate date format mm 2fdd 2fyyyy javascriptvalidation datehow to check date format in javascriptformat validation for date fields javascriptvalid date jsjavascript how to validate date javascript check date formatjs is date validjs check is valid datevalidate a date javascriptvalidate format date javascriptvalidate a date in javascriptjs test if valid datevalidate date input in javascriptvalidate date dd 2fmm 2fyyyy in javascripthow to validate date input for teenagers in jsdate check if valid in javascriptjs validate date text fieldhow to validate current date in javascripthow to validate date in javscriptjavascript is valid date stringvalidate datetime javascriptjavascript how to check if date is validvalidate date javascriptcheck if date valid javascriptdate is valid javascriptvalidate date time javascriptvalidate js date examplehtml date validation test if date is valid javascriptcheck if string is valid date format javascriptdate function validate datejs how to validate date stringhow to validate dd mm yyyy format date in javascriptvalidate datetime in javascriptjs check date is validis valid date javascriptvalidate year in javascriptjs validate date regexjavascript validate mm validhow to check if a given string is a valid date in javascriptjavascript validate date stringdate dd mm yy if conditioncheck format date javascriptgenerate valid date from date and time jsvalid date format javascriptcheck if date format is valid javascriptjavascript verify date string is validjs date validationdate format form validationis valid date function jshow to check a date is valid in javascriptvalidate valid date javascriptjs date is validdate validation check in javascriptcheck if valid date string javascripthow to validate date input in js jquery match date formatverify if date is valid jsdate validate in javascriptvalidate string is date javascripthow to validate uct date javascripttypescript date validationvalidate dates javascriptnew function with name valid date 28 24month 2c 24day 2c 24year 29vulidate datecheck is valid date javascriptdate validation in htmlverify valid date javascripthow to validate date in javascript formhow to validate date in javascriptverify datevalidate date which is in any format javascriptjavascript check if input was the right formatvalidate date input field only to accept the validated formathow to check date format validation in javascriptdate validation using jscheck if string is a valid date javascriptcurrent date validation in javascripthow to validate date input in javascriptcheck valid date in jsnew date in javascript validationjavascript validate date format dd mm yyyy withbooleanjs date validatevalide date regex javascriptcheck if the date is valid in javascriptjavascript validate dates libaryhow to check date o object ate formathow to check date is valid or not in javascriptvalidate date format in javascriptvalidating dates in javascriptcheck the condition if the date value format is not equal to yyyy mm dd in javascriptvalidate js datemethod date validator jsjavascript validate date dd 2fmm 2fyyyyvalidating date in javascript discriptionjs check to see if date is a certain formatregex for day name validation in javascriptdate checking in javascriptjs check if string is a valid dateinput date check if is the correct formatvalidate mm 2fdd 2fyyyy date format javascriptjs a pattern for testing dates in this format 3a mm 2fdd 2fyyycheck for valid date in javascriptvalidate form date javascriptjavascript validate date this code use fullfunction for date validation in javascriptcheck if date is valid jshow to check if string is valid date in javascriptjavascript validate date this code 22use full 22verify it is a date jsvalidate date nodejsjs validate full date text fieldjs create date validationcheck if string is valid date javascriptvalidate from date and to date in jshow to check valid date in javascripthow to validate date field in javascriptcheck javascript date validjavascript valid datecheck if a string contains a valid year javascriptjavascript check is valid datedate is valid jsdate javascript validationhow to create form date to date validation in javascriptcheck if a field is in dd 2fmm 2fyyyyhow to validate input date jsvalidate input date javascriptdate validateionsjavascript if valid datenode verify date formatdate pattern js validatorvalidator js date format helphow to validate date string in nodecheck if date is valid in jsvalidor date time nodejs validate datetypescript validate date formatjavascript validation for dd 2fmm 2fyyyy date formatcheck date format in jsbirth date format regex jsjavascript check date is validvalidatorjs 2b dateis validate date time dd 2fmm 2fyyyy in javascriptjavascript is date validcheck if date string is valid javascriptcheck if there is any valid date in the file such as mm 2fdd 2fyyyy is date valid javascriptjavascript check date format is validjs check if a date is validjs date format checkvalidate the date format using javascriptvalide date in jshow to check the date is valid in htmljs check if date is validvalidate date object javascriptvalidating date format in javascriptvalidate date nodejs with new datedate format input javascript validationjs is valid datetype the right date javascript validationhow to add date validation in javascript inhow to validate any format in javascriptjs check if valid datevalid date validation javascriptvalidate dates in javascripthow to make a validation date check for javascriptvalidate date field in javascriptjavascript past date validationtypescript year validatorhtml input validation isdatehow to validate if a date is valid jsjavascript validate date formatvalidate format jsdate field verification using javascriptjavascript validate if date is validhow to validate date using pattern in javascriptnodejs validate datevalid date string javascriptjs how to check if date is validassert format date yyyy mm dd jsform validate of date and time in javascriptdate validation javascript for type datejavascript validation date inputjavascript validation datejavascript how to validate valid datejavascript validate a valid datejs validate date stringhtml check date formatjs valid datecheck whether string is a valid date in javascriptcheck date is valid javascriptcheck if a valid date javascriptdate validation in javascriptvalidate mm 2fyy in javascriptjavascript check date format validvalid date format in jshow to check string format as in mm 2fdd 2fyyyydate input validation htmlhow to validate the date in javascriptjavascript date validation for past datejavascript validatordationverify date format javascriptjavascript date how to know if validcheck valid date jsjavascript date validvalidate date in javascriptis valid date jsdob validation in javascripthow to check if a string is a valid date in javascriptvalidate date in javascript html input textdate of birth validation in htmlhow to check in js if valid date in stringjavascript cheak if date is validcheck if date is valid date javascriptvalidate string as date in javascriptcheck valid date format in javascriptvalid date in jsdate validation in dd format using javascriptcheck for a valid date in jsnodejs validate date formatjavascript validator datejavascript check valid datejavascript how to check for valid datevalidate if date is valid javascriptjavascript check yyyy formatdate validation for jshow to valid date in javascriptcheck if string date is valid javascriptcheck if date format is correct javascriptjavascript date validationdate asking in javascripthow to check if input date format is correct or not using javascripthow to check date validation in javascriptcheck if date is valid javscriptvalidate date is valid javascriptcheck if a date is valid javascriptcheck date javascript validationdate validator jsjavascript varify the date formatjavasript valid datejavascript check if valid datevalidate month and year javascriptjavascript check formatjs check if string is valid datevalidate date format in javascript mm 2fdd 2fyyyycheck if the date is valid jschaeck date string is valid in javascriptregexp javascript date validation with if date format jsfunction validdate 28 29how to check for date format before converting it javascriptcheck date valid javascriptjs how to validate datefrom date and to date validation in jscheck is a date valid javascriptdate validation in jstest valid date javascriptjavascript date check if validhow to check valid date javascriptjavascript valid date formatcheck if valid date jsvalidate date with javascripthow to validate datea in javascriptjs check if string valid datejavascript if new date format is correctcheck if date time string is valid date jscheck date is valid or not javascripthtml date valid date listdate validation in dd mm format using javascriptyear validation javascriptfunction validdate 28 29 jsvalidate date in htmljs to validate datejs date regex validatejavascript if string is valid date123 is valid date javascriptjavascript check is date validjs validate date formatjs check if valide datedate object javascript valid methodvalidate current and end date in javascriptmm dd yyyy input jsjavascript validate datehow to validate input type 3ddate in javascriptjavascript test for valid datedate string validation in javascriptjs to check if date is validvalidate datejavascript check it date is validjavascript validation date examplecheck validate date javascriptvalidates that the input string is a valid date formatted dd 2fmm 2fyyyyjs check dateformatcheck if year is valid date javascriptjs date validatervalidate jscript datechecking when a deadline is due in html and javascriptvalidatorjs datehow to check if date is valid javascriptcheck if date is valid javascriptdate validationjs new date 28string 29 tcheck if valid datejavascript valid datesvalidation date javascripthow to validate date javascriptow js validate date formatvalidate a date from form nodejsis date valid jsjavascript check pattern day 2fmonth 2fyearcheck if valid date jsassert format date jsjs check if date string is validvalidate different types of date with javascriptjs valid date stringjavascript if date is validhow to check if date is valid in javascriptvalidate date jsexplanation for date javascript validationhow to check for valid date in javascriptjs validate is string is a datehow to check if it 27s a valid date javascriptpast date validation in javascriptjavascript validate date