I need to use a regex to validate the next rules :
•The first 8 characters should be in ‘date’ format of YYYYMMDD without separators
•Total expression length should be 13 characters
I use internal regular expressions manager
Java code example :
import java.util.regex.Pattern;
public class TestDate {
public static final Pattern datePattern = Pattern.compile("** Need RegEx **");
public static void main(String[] args) {
System.out.println(datePattern.matcher("1996022965789").matches());
// -Wrong value
System.out.println(datePattern.matcher("1996022865789").matches());
// -Correct value
}
}
Examples for input values and expected results :
Input: 201909866666 Result: Wrong Length
Input: 2019022966666 Result: Wrong date value
Input: 2019022866666 Result: correct