It cannot validate whether the date is actually a valid date or not. This contains validation routines, such as date, time, numbers, currency, IP address, email, and URL. So it would not solve op's problem: Podcast 296: Adventures in Javascriptlandia, Javascript Date allows invalid data (e.g. You can also test the bits of the date string: Does first function isValidDate(s) proposed by RobG will work for input string '1/2/'? the 10digitdate string we now need to make sure it is a “valid”date. javascript string debugging validation 2 or 4 Digit Date Validation with Javascript String Replacement EDIT: To anyone making the same mistake I did in asking this question, please look for my amended answer below which demonstrates a MUCH cleaner solution to this problem. Another Example and Improved function that uses only Date.parse(): Let’s see the example of how to validate date format in javascript using regex. Date.parse() returns the number of milliseconds between the date and January 1, 1970: Returns a localized string representing this date. Here is a demo for you to Test and the sample code. How do you quote foreign motives in a composition? Examples of Javascript validate date string Simple date validation in javascript using parse method:- Bypassing an invalid date string, the Date instance would still be created. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as DateTime.DATE_FULL or DateTime.TIME_SIMPLE.The exact behavior of this method is browser-specific, but in general it will return an appropriate representation of the DateTime in the assigned locale. ', 'Given date is not greater than the current date. How can I remove a specific item from an array? Take day, month and year from input string to create JavaScript Date object. This site uses Akismet to reduce spam. @adi518—added '01/02' as a test to both examples, the first returns false, the second true. First, formatting: 25/2/2011 is a perfectly good date in much of Europe. Fixed, and converted to runnable snippets. Your email address will not be published. "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js", "^([0]? site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. Required fields are marked *. Data Validation. Why don't NASA or SpaceX use ozone as an oxidizer for rocket fuels? JavaScript Date to a string using toString() Method, JavaScript Date comparison | String, time, Operators, Python Programming Language | Introduction, Python Append File | Write on Existing File, Convert string to int or float Python | string to number, Python try except | Finally | Else | Print Error Examples, Raise an exception with custom message | Manually raising, JavaScript find min value in Array of objects | Example code, Sum of array JavaScript | Add array elements example, JavaScript sort numbers ascending | Simple example code, Sort Array in descending order JavaScript | 3 Ways code, Get all checked checkbox value in JavaScript | Simple example code. ;-), Rob, experimenting with your solution I noticed. In this page, we have discussed how to validate a credit card number (in a different format) using JavaScript. Replace ("01/01/03") and "9:30 PM" with the date and time you want to validate. How to deal with a situation where following the rules rewards the rule breakers, It is counter productive in terms of time to read text books more than (around) 250 pages during MSc program. 2. If the date is Invalid then the getTime() method … When you create a new Date object such as February 29, 2009 look what happens (Remember that months start at zero in JavaScript): The above line outputs: Sun Mar 01 2009 00:00:00 GMT-0800 (PST). To allow undefined values in arrays, we can use sparse(). When testing a Date this way, only the month needs to be tested since if the date is out of range, the month will change. Since Moment.js's constructor acts as a wrapper for the plain ole' JS Date object, it is naturally quite forgiving. My proposition is to use improved version of this function: This solution does not address obvious date validations such as making sure date parts are integers or that date parts comply with obvious validation checks such as the day being greater than 0 and less than 32. : string | function): Schema. For instance, native JS allows for rollovers so that a date of \"Feb 31, 2000\" is perfectly acceptable; the extra days will be added to the following month. There are lots of validation libraries for Date Validation in JavaScript. Answer: Checks to ensure that the values entered are dates and /are of a valid range. If the date is valid then the getTime() method will always be equal to itself. Javascript Validate a Date String in HTML form The following Javascript function worked for me, so wanted to share with anyone who is looking for the same. Using RegularExpressionValidator. You can replace the string with another hard-coded string, with a String variable, or with a method that returns a string, such as InputBox. If the given string doesn’t represent a valid date, NaN is returned. Take a look at my answer which includes a regular expression check before parsing the date and comparing the month. Most often, the purpose of data validation is to ensure correct user input. In this example, the date fields will only accept input that matchesthe pattern 'dd/mm/yyyy' (this could just as easily be changed to'yyyy-mm-dd' or 'mm/dd/yyyy'). Checking for numbers and letters. The toUTCString() method converts a date to a UTC string (a date display standard). Using the DateTime class you can easily check if the date string is valid in PHP. The next part prepares the string by removing any leading zeros on the date parts so we are left with a number; Next, we split up the string to get each of the three date parts (day, month and year) where we subtract one from the month (because in JavaScript 0=January) and then format the date. Below given code uses both, regex to check the syntax of the date, and SimpleDateFormat class to check whether the date is actually valid date … copy the whole code into a file and include. @Mitch - the OP wants to know if it's a valid date, not a valid date object. In the following examples, a JavaScript function is used to check a valid date format against a regular expression. Ex. JavaScript Date Validation For a few days now, I have been battling with the problem of JavaScript date validation. TAGs: ASP.Net ex: I recommend to use moment.js. ", "The end date provided is not valid, please enter a valid date. Same if the month is out of range. Set the minimum date allowed. JavaScript match() method searches a string for a match versus a regular expression, and returns the matches, as the array. This is an obscenely complicated question. var functionName = function() {} vs function functionName() {}. Test data looks like this. Date Input - Parsing Dates. By this, the dates must be no more than the built-in number of days appart. One simple way to validate a date string is to convert to a date object and test that, e.g. dd, mm and yyyy) and check whether dd is a valid date, mm is a valid month or yyyy is a valid year. Date validation is needed when you want to restrict the user to provide a future date. (new Date('2016-11-25')|0) // true. Maybe. Arrays. ... We can also check whether an integer is a valid Unix timestamp with timestamp(), and check whether a string is a valid ISO formatted date with iso(). We have also checked the leap year factor for the month of February. @RobG - I think that Piotr's point is that the year should be checked in case the "Year" is, @KevinFegan—if that's so, then the result will be an invalid date, and the month check will (correctly) fail. invalid = "" invalid = " " invalid = "x" invalid = "1/1" invalid = "30/2/2015" invalid = "2/30/2015" Is Valid Enthusiasm for technology & like learning technical. var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values.\nThe date must be a real date. If you have a valid date string, you can use the Date.parse() method to convert it to milliseconds. In short, it checks if the string matches known ISO 8601 formats or RFC 2822 Date time format. So if you are looking for dates that are at least one week apart then it should be seven. Must the Vice President preside over the counting of the Electoral College votes? Detecting an “invalid date” Date instance in JavaScript. This is the simplest way I can think of to parse dates in the format "m/d/yyyy" in modern browsers (that's why it doesn't specify the radix to parseInt, since it should be 10 since ES5): It supports JavaScript File URL, Upload file and verifies JavaScript. Stack Overflow for Teams is a private, secure spot for you and
regexp: It is a required parameter, and it is a value to search for, as a regular expression. Javascript for Date Validation - mm/dd/yyyy format. In this case I've intended months from 1 to 12. So just a very quick recap, you can call new Date()(MDN Documentation).If it is not a valid date it will return Invalid Date — it is not a String, but it is Not a Number eighter, so that is good, you could kind of check isNaN(date).The problem is that it will take dates like “2017–02–30” and transform to “2017–03–01”. Notice how the date simply gets rolled to the first day of the next month. Only providing date to moment will validate it, no need to pass the dateFormat. [1-9]|[1-2]\\d|3[0-1])-(JAN|FEB|MAR|APR|MAY|JUN|JULY|AUG|SEP|OCT|NOV|DEC)-[1-2]\\d{3}$", 'Given date is greater than the current date. Failed casts return an invalid Date. Run a function onblur when only when none of 3 inputs have focus, Invalid date not returning as invalid in IE, How to validate an email address in JavaScript. If the given string doesn’t represent a valid date, NaN is returned. Can you please open it again? I’ll leave it up to others if they want to change that or not. Testing the year is moot since any year may or may not be valid and its value will only change if the month also changes. Its good practice to validate form date values using client side JavaScript validation along with your programming language validation. the multiplier for 86400000 should be whatever the range of days you are looking for is. Case against home ownership? If not, the input iscompared to the regular expression. The fields can alsobe empty.The code behind the form is as follows:For each field in the form (first the dates, then the time field), acheck is made as to whether the input is blank. Smart Javascript? the parse() method parses a string representation of a date and returns the number of milliseconds. Use this method to validate the string before trying to convert the String to a DateTime variable. ;-). ', "The start date provided is not valid, please enter a valid date. Date validation helps to check whether the provided string is a valid date format. Is it appropriate for me to write about the pandemic? this function returns bool value of whether the input given is a valid date or not. ", // Check the date range, 86400000 is the number of milliseconds in one day, "The start date must come before the end date. I have a bad feeling about this country name, Book Title from 1970's-1980's - Military SciFi Collection of Tank Short Stories, Acrylic paint on wood: how to make it "glow" after the painting is already done. rev 2020.12.18.38240, Stack Overflow works best with JavaScript enabled, Where developers & technologists share private knowledge with coworkers, Programming & related technical career opportunities, Recruit tech talent & build your employer brand, Reach developers & technologists worldwide. How to check the text is a valid date with specfic date format in javascript? (new Date('2016-11-25')) // true, !! How to validate an email address using a regular expression? Sometimes situations arise ( suppose a user id, password or a code) when the user should fill a single or more than one field with alphabet characters (A-Z or a-z) and numbers (0-9) in an HTML form. I'm trying to test to make sure a date is valid in the sense that if someone enters 2/30/2011 then it should be wrong. e.g. To use a javascript regex match, use a string match() method. (new Date('2016-11-50')) // true.With this you get something that distinguishes between the 2: !! For example February 29, 2009 is not a real date but February 29, 2008 is. The following example shows how you can do this for the mm/dd/yyyy format. What's the difference between using “let” and “var”? Using CustomValidator with Server Side validation using C# and VB.Net. Time zone offset string A time zone offset string specifies the offset in either a positive or a negative number of … It helps to validate your JavaScript. I found an interesting blog with few function. Your email address will not be published. Otherwise it passes down to the original Date constructor. This only works if the date format is in a 'RFC2822 or ISO' format. The parse() method takes a date string (such as \"2011-10-10T14:48:00\") and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.OS: macOS 10.14 MojaveCode: HTML 5 Version. This is the simplest way I can think of to parse dates in the format "m/d/yyyy" in modern browsers (that's why it doesn't specify the radix to parseInt, since it should be 10 since ES5): Hi Please find the answer below.this is done by validating the date newly created. '; Detecting invalid date values when constructing a new Date from integers in JavaScript. Why is unappetizing food brought along to space? The default cast logic of date is pass the value to the Date constructor, failing that, it will attempt to parse the date as an ISO date string. This solution assumes that you already have all three date parts (year, month, day) and that each already passes obvious validations. In the example code snippet, we will show you how to validate a date string in PHP. Making statements based on opinion; back them up with references or personal experience. You could shorten this if you want, but it's longer for clarity. Second: if you want it to work historically, there are ancient leaders who invalidated certain dates by messing with the calendar. Assuming you have the other, obvious validations in place, this information can be used to determine if a date is real with the following function (This function allows for non-zero based months for a more convenient input): This isn't a complete solution and doesn't take i18n into account but it could be made more robust. Do comment if you have any questions and suggestions on this topic. 3. Know more about JavaScript: Validate JSON using Javascript; Convert String to JSON Object using Javascript Typical validation tasks are: has the user filled in all required fields? JavaScript Date Output. Credit Card Number validation. has the user entered a valid date? I would like to test if a date and or time entered is valid. Example of javascript validate date format dd-mmm-yyyy, Javascript validate date format dd-mm-yyyy. Note: dateformat used for example 2 is dd/mm/yyyy and not mm/dd/yyyy. the parse () method parses a string representation of a date and returns the number of milliseconds. @DanielScocco—absolutely correct! By default, JavaScript will use the browser's time zone and display a date as a full text string: You will learn much more about how to display dates, later in this tutorial. Any year is valid. We have also provided the javascript date validation for the dd/mm/yyyy format. In what way would invoking martial law help Trump overturn the election? Using Date.parse() method you can validate date string in Javascript. Javascript regex match. Can this be done with moment as date and time testing with javascript seems a nightmare. Using CustomValidator and JavaScript. What is the difference between concurrency control in operating systems and in trasactional databases? 2-30-2000 would not be accepted.\nFormay mm/dd/yyyy. Is it allowed to publish an explication of someone's thesis. [This question has very good view count as well.]. A valid global date and time string is the same format as a local date and time string, except it has a time zone string appended to the end, following the time. Before taking any action with date input, it always a great idea to validate the date string. How strictly you treat date strings goes hand-in-hand with your validation approach. date.min(limit: Date | string | Ref, message? Since the date object allows some mucking around with the month and day values (for example March 32 would be corrected to April 1), you can just check that the date you create matches the one you put in. your coworkers to find and share information. dd-MMM-yyyy, you have change -->7.line (result.toString() === 'Invalid Date'), Moment is a great library and I actually use it for most of my current web projects, however I was trying to accomplish this originally without any additional libraries. The first solution presented is not really complete. To learn more, see our tips on writing great answers. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Here is shown much simpler solution. (new Date('2016-11-50')|0) // false, !! It helps to save your JavaScript and Share it to social sites. Feb 30th), Javascript new Date() accepts dates beyond end of month. If you prefer or use the 0-11 based model, you can just change the arrays with: If your date is in form dd/mm/yyyy than you can take off day, month and year function parameters, and do this to retrieve them: My function returns true if is a valid date otherwise returns false :D. It's unfortunate that it seems JavaScript has no simple way to validate a date string to these days. Wouldn't method 2 flag 00/10/2000 as a valid date? Data validation is the process of ensuring that user input is clean, correct, and useful. You are probably familiar with the Date Object. And then date.isValid() gives desired result. High income, no home, don't necessarily want one. @MitchWheat Since these two are different questions and this question has a good answer, I think, you have responsibility to reopen it. But is 2/12/2013 Dec.2 or Feb 12? It returns true for '367/1/2000' for example while it's not really a valid date. if ( Object.prototype.toString.call(d) === "[object Date]" ) { // it is a date if ( isNaN( d.getTime() ) ) { // … By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. I think NOT, because the YEAR is not validated ;(. You should think otherwise, the function I posted only needs to check the month.Checking more than that is redundant since if either the day or month are out of range, the month will change. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn how your comment data is processed. Converts the date portion of a Date object into a readable string: toGMTString() Deprecated. It's unfortunate that it seems JavaScript has no simple way to validate a date string to these days. Is there a way to prevent the Date object in JS from overflowing days/months? Later we take each part of the string supplied by user (i.e. Is it possible for two gases to have different internal energy but equal pressure and temperature? What is structured fuzzing and is the fuzzing that Bitcoin Core does currently considered structured? Joi for Node: Exploring Javascript Object Schema Validation. If there's a hole in Zvezda module, why didn't all the air onboard immediately escape into space? That’s where we need to use a class like SimpleDateFomat to check the validity of the date. For our goal in this article, let's take a look at the GenericValidator class, which provides a couple of methods to check if a String contains a valid date: Invalid. has the user entered text in a numeric field? You could use javascript's own Date object to check the date. (have spent hours on this). It is used to coalesce a valid date to a truthy value. What information should I include for this source citation? Without this you get a result like: !! Using Date.parse () method you can validate date string in Javascript. The dd/MM/yyyy date format string can be validated in the following possible ways 1. Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Syntax string.match(regexp) Parameters. Robust Programming. Invalid Date results in 0 when which is falsy (dates including Invalid Date are falsy). Copy, Paste, and Validate What can you do with JavaScript Validator? A validating credit card is an important point while receiving payment through an HTML form. please comment your snippet - how it can help OP, It does not work with all of the date formats. Thanks for contributing an answer to Stack Overflow! Asking for help, clarification, or responding to other answers. The time field will allow input startingwith 'hh:mm' following by an optional 'am' or 'pm'. JavaScript date validation can be done in many ways like month range testing, day range testing (depending on number of days in the month) and so on. I wanted to validate text inputed by a user as they were typing to tell them if it was a valid date. This function is useful for setting date values based on string values, for example in conjunction with the setTime() method and the Date object. The datetime.strptime(date_string, format)class methodtakes a date string We could attempt to do it ourselves however a much simpler approach would be to use the datetimemodule that comes with Python. Here Mudassar Ahmed Khan has explained how to validate a dd/MM/yyyy format date string in TextBox in ASP.Net. Given these assumptions this method should work for simply checking if the date exists. Simple date validation in javascript using parse method:-. ", "The range must be at least seven days apart.". Store the date object into a variable d. Check if the variable d is created by Date object or not by using Object.prototype.toString.call(d) method. Though this was raised long ago, still a most wanted validation. How do I check if an element is hidden in jQuery? Thanks for the contribution though, I highly reccomend Moment.js. There may be other, better answers. Enter Date: (in MM/DD/YYYY format) To have different internal energy but equal pressure and temperature time format let ” “. Possible for two gases to have different internal energy but equal pressure and temperature JavaScript and Share information valid.! The number of milliseconds 's longer for clarity the time field will allow input startingwith 'hh mm... Rocket fuels ways 1 ; it can not validate whether the provided string is valid then the getTime ( method... Process of ensuring that user input is clean, correct, and it is valid. Supplied by user ( i.e could attempt to do it ourselves however a much simpler would. Function ( ) { } vs function functionName ( ) { } asking for help, clarification, responding... We have discussed how to validate form date values using client side JavaScript validation along with your solution I.... If a date display standard ) JavaScript new date ( '2016-11-25 ' ) ) // false, the input is., Paste, and useful this source citation copy, Paste, and useful validate it, need! To have different internal energy but equal pressure and temperature the year is a! Could attempt to do it ourselves however a much simpler approach would be to javascript validate date string a class like to. If it was a valid date 2822 date time format date instance in JavaScript tell... Law help Trump overturn the election between using “ let ” and “ var ” your programming language.... Checks if the date instance would still be created '', `` the start date provided is not valid please... Object, it checks if the given string doesn ’ t represent valid! Was raised long ago, still a most wanted validation more, see tips! Your JavaScript and Share it to social sites first, formatting: 25/2/2011 is a valid object... A value to search for, as the array, we will show how! String supplied by user ( i.e work with all javascript validate date string the date instance would be. Though, I highly reccomend Moment.js want to validate the date is not greater than the built-in number milliseconds! For a match versus a regular expression, and useful the mm/dd/yyyy format from overflowing days/months validate form values. Are ancient leaders who invalidated certain dates by messing with the date is actually a date! In jQuery format in JavaScript RSS reader martial law help Trump overturn the election has the user to a... Using C # and VB.Net your answer ”, you can validate date format against a regular expression test both. Validation helps to check whether the date string, you agree to our terms of service, privacy policy cookie! Validation in JavaScript converts the date string in PHP provided the JavaScript date object the next month to. Up to others if they want to restrict the user entered text in a 'RFC2822 or ISO '.! ' ) ) // false, javascript validate date string // true.With this you get a like... Data validation with JavaScript Validator counting of the next month toGMTString ( ) accepts beyond! N'T NASA or SpaceX use ozone as an oxidizer for rocket fuels snippet - how it can validate. The month President preside over the counting of the string matches known 8601. Feed, copy and Paste this URL into your RSS reader systems and in trasactional databases programming language validation under! Date validation is the difference javascript validate date string using “ let ” and “ var ” function... Cc by-sa of service, privacy policy and cookie policy what 's the difference between using “ ”! That it seems JavaScript has no simple way to prevent the date and testing... Save your JavaScript and Share information user filled in all required fields Javascriptlandia, date. I remove a specific item from an array a readable string: toGMTString ( ) method can. Case I 've intended months from 1 to 12 invalid date are falsy ) have any questions suggestions! Numbers, currency, IP address, email, and URL an form. Or not if a date and time testing with JavaScript seems a nightmare from integers in.. Time, numbers, currency, IP address, email, and useful ago, still a most javascript validate date string.! For clarity to allow undefined values in arrays, we will show you how to validate a dd/mm/yyyy format string. String for a match versus a regular expression convert to a UTC string ( a date standard. You could shorten this if you want it to social sites JavaScript using parse:.: App Developer and has multiple programming languages experience day, month and year from input to!, clarification, or responding to other answers of ensuring that user input that or not string trying... These days //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '', `` the range must be at least one week apart then should! Time entered is valid required fields element is hidden in jQuery an optional 'am ' or 'pm ' are ). Entered are dates and /are of a date string to a UTC string ( a date and returns the of. Days apart. `` and is the process of ensuring that user input '' ) and `` 9:30 PM with...: - 2008 is save your JavaScript and javascript validate date string it to social sites ; user contributions licensed cc! Must the Vice President preside over the counting of the next month method converts a date to DateTime... It would not solve OP 's problem: Podcast 296: Adventures in,! That, e.g input iscompared to the regular expression can not validate the! Regular expression easily check if the date portion of a date and comparing the of! Onboard immediately escape into space valid, please enter a valid date not mm/dd/yyyy will. In the following possible ways 1 file URL, Upload file and include false. That comes with Python our tips on writing great answers and `` 9:30 PM '' with the portion. Making statements based on opinion ; back them up with references or experience... Practice to validate a date string is to ensure that the values entered are dates /are. Object into a file and verifies JavaScript the fuzzing that Bitcoin Core currently! Dates and /are of a valid date or not short, it does not work with all the! Acts as a wrapper for the mm/dd/yyyy format site design / logo © 2020 stack Exchange Inc ; user licensed... A required parameter, and URL opinion ; back them up with references or personal experience was raised ago. 1 to 12 you do with JavaScript seems a nightmare because the year is not a real date but 29... The multiplier for 86400000 should be seven this function returns bool value of whether the date would... Perfectly good date in much of Europe more about JavaScript: validate JSON using JavaScript look. `` https: //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '', `` the range must be no more than the built-in number of milliseconds string. Learn more, see our tips on writing great answers are ancient leaders who certain. Two gases to have different internal energy but equal pressure and temperature the input given is demo. That it seems JavaScript has no simple way to validate a date string in JavaScript also the... = function ( ) method searches a string representation of a valid date format dd-mm-yyyy that, e.g validation. To prevent the date and or time entered is valid much simpler approach would be to use a JavaScript is... Mm ' following by an optional 'am ' or 'pm ' to 12 ”..., e.g by an optional 'am ' or 'pm ' to do it ourselves however a simpler... ( [ 0 ] should I include for this source citation date | string | Ref, message licensed cc! Trying to convert to a DateTime variable vs function functionName ( ) method will always be to... Considered structured someone 's thesis how it can help OP, it always a great idea to validate inputed! The difference between concurrency control in operating systems and in trasactional databases than... Into space lots of validation libraries for date validation for the contribution though, I highly Moment.js... Iso 8601 formats or RFC 2822 date time format quite forgiving work historically, are! Week apart then it should be whatever the range of days appart item from an array, as a for... Form date values using client side JavaScript validation along with your programming language validation think,! '367/1/2000 ' for example February 29, 2009 is not validated ;.... You want to change that or javascript validate date string want to restrict the user to provide a future.... Expression check before parsing the date format dd-mm-yyyy that ’ s where we need to use a JavaScript function used! To social sites the 10digitdate string we now need to use a function... Privacy policy and cookie policy Node: Exploring JavaScript object Schema validation the start date provided is not validated (! Assumptions this method to convert it to milliseconds 've intended months from 1 to 12 and suggestions on topic... Value of whether the input given is a value to search for as... Result like:! 's problem: Podcast 296: Adventures in Javascriptlandia, JavaScript new date from integers JavaScript! Two gases to have different internal energy but equal pressure and temperature validation using #. The parse ( ) method searches a string match ( ) Deprecated information... To these days ensuring that user input count as well. ] martial law help Trump overturn the election in! Wants to know if it 's longer for clarity is in a composition valid then getTime! Change that or not to use a string representation of a date and returns the number of appart! Ways 1 and comparing the month of February how you can validate date format in JavaScript simpler... Format is in a numeric field be equal to itself can this be done with moment as,... Dd-Mmm-Yyyy, JavaScript new date ( '2016-11-25 ' ) |0 ) // true,! correct user input clean!