Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

validate date regex

/^([1-2][0-9]|3[0-1]|0?[1-9])([-./ ])(1[0-2]|0?[1-9])(2)([d]{4}|[d]{2})$/
Comment

regex pattern for date validation

// Pattern validates that: 
// day is from 01 to 31
// month is from 01 to 12
// year must be 19yy or 20yy
// delimiter is / or - or .
// date format is dd-mm-yyyy or yyyy-mm-dd
String dateRegex =
                "((0[1-9]|[12][0-9]|3[01])" +   //dd from 01 to 31
                "[/.-]" +                       // - or . or /
                "([01][0-9])" +                 //mm from 01 to 12
                "[/.-]" +                       // - or . or /
                "(19[0-9]{2}|20[0-9]{2}))" +    //yyyy must be 19yy or 20yy

                "|" +                           //or

                "((19[0-9]{2}|20[0-9]{2})" +    //yyyy must be 19yy or 20yy
                "[/.-]" +                       // - or . or /
                "([01][0-9])" +                 //mm from 01 to 12
                "[/.-]" +                       // - or . or /
                "(0[1-9]|[12][0-9]|3[01]))";    //dd from 01 to 31
                
Comment

PREVIOUS NEXT
Code Example
Java :: how to get the average from a list in java 
Java :: math library java 
Java :: string to float java 
Java :: uppercase string java 
Java :: Get the last Friday of a month in Java 
Java :: localdate java 
Java :: start activity for result deprecated 
Java :: simple login password and username java 
Java :: try block in java 
Java :: prepared statement update 
Java :: java scanner string nextline after nextint 
Java :: java how to get all threads 
Java :: reading from a text file in java 
Java :: java gridpane background color 
Java :: remove last <br/ from string java 
Java :: tableau de classe java 
Java :: while loop java 
Java :: java int 
Java :: string programs in java 
Java :: string vs stringbuffer 
Java :: imageview height based on screen size 
Java :: measure running time of a statement java 
Java :: java for each loop 
Java :: fill two dimensional array column by column java 
Java :: java time difference 
Java :: set source image in android studio 
Java :: hadoop-master error java_home is not set and could not be found 
Java :: sorting in java 
Java :: this keyword in java 
Java :: find minimum number in java 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =