i have this format for dates yyyy-MM-dd
and generating the following reged
/^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$
This is generated in java using the following where i replace the format with regex
String format = getDisplayDateFormat( formatType );
format = format.replaceAll("\\-","\\\\-");
format = format.replaceAll("y","[0-9]");
format = format.replaceAll("M","[0-9]");
format = format.replaceAll("d","[0-9]");
return "^" + format + "$";
If i run this through a regex validator its fine, but chrome is giving the following error
Pattern attribute value ^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$ is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$/: Invalid escape
edit to include html
<input type="text" value="2020-04-21" placeholder="yyyy-mm-dd" pattern="^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$" data-minimum-value="2020-08-10" data-maximum-value="2020-08-13"id="F112407" maxlength="10" data-date-format="YYYY-MM-DD" >