Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to @mplungjan. I have upvoted that answer.</p> <p>@mplungjan approach (first suggested) is listed in <a href="http://jsfiddle.net/Lijo/uzSU6/7/" rel="nofollow noreferrer">http://jsfiddle.net/Lijo/uzSU6/7/</a>. This was failed in IE8 for one scenario - <a href="http://jsfiddle.net/Lijo/uzSU6/12/" rel="nofollow noreferrer">http://jsfiddle.net/Lijo/uzSU6/12/</a>.</p> <p>So I have used a slightly different approach after referring <a href="https://stackoverflow.com/questions/5812220/test-if-date-is-valid">How to validate a date?</a>. See it here <a href="http://jsfiddle.net/Lijo/uzSU6/20/" rel="nofollow noreferrer">http://jsfiddle.net/Lijo/uzSU6/20/</a> </p> <p><strong>EDIT</strong></p> <p>Please refer <a href="http://jsfiddle.net/uzSU6/37/" rel="nofollow noreferrer">http://jsfiddle.net/uzSU6/37/</a> for scenarios that handle blank spaces</p> <p>Feel free to give your suggestions/ challenges with this approach.</p> <p><strong>References</strong></p> <ol> <li><a href="https://stackoverflow.com/questions/13911311/check-whether-white-spaces-exist-without-using-trim">Check whether white spaces exist without using trim</a></li> <li><a href="https://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use/">Which equals operator (== vs ===) should be used in JavaScript comparisons?</a></li> <li><a href="https://stackoverflow.com/questions/5812220/test-if-date-is-valid">How to validate a date?</a></li> </ol> <p><strong>CODE</strong></p> <pre><code>function isValidDate(s) { var bits = s.split('/'); if(s.indexOf(' ') != -1) { //White space exists in the original date string return false; } //Javascript month starts at zero var d = new Date(bits[2], bits[0] - 1, bits[1]); if ( isNaN( Number(bits[2]) ) ) { //Year is not valid number return false; } if ( Number(bits[2]) &lt; 1 ) { //Year should be greater than zero return false; } //1. Check whether the year is a Number //2. Check whether the date parts are eqaul to original date components //3. Check whether d is valid return d &amp;&amp; ( (d.getMonth() + 1) == bits[0]) &amp;&amp; (d.getDate() == Number(bits[1]) ); } </code></pre> <p>​</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload