Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A regular expression alone cannot validate a date because of the different number of days in months - especially for leap years.</p> <pre><code>/^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/ </code></pre> <p>but above regex solves your problem of allowing - or / based on these format dd-mm-yyyy or dd/mm/yyyy</p> <p>Here are some examples</p> <pre><code>//Date d/m/yy and dd/mm/yyyy //1/1/00 through 31/12/99 and 01/01/1900 through 31/12/2099 //Matches invalid dates such as February 31st '\b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}\b' //Date dd/mm/yyyy //01/01/1900 through 31/12/2099 //Matches invalid dates such as February 31st '(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}' //Date m/d/y and mm/dd/yyyy //1/1/99 through 12/31/99 and 01/01/1900 through 12/31/2099 //Matches invalid dates such as February 31st //Accepts dashes, spaces, forward slashes and dots as date separators '\b(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}\b' //Date mm/dd/yyyy //01/01/1900 through 12/31/2099 //Matches invalid dates such as February 31st '(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}' //Date yy-m-d or yyyy-mm-dd //00-1-1 through 99-12-31 and 1900-01-01 through 2099-12-31 //Matches invalid dates such as February 31st '\b(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])\b' //Date yyyy-mm-dd //1900-01-01 through 2099-12-31 //Matches invalid dates such as February 31st '(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])' </code></pre> <ul> <li><a href="http://www.roscripts.com/PHP_regular_expressions_examples-136.html" rel="nofollow">http://www.roscripts.com/PHP_regular_expressions_examples-136.html</a></li> </ul>
    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. 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