Regular expression not working properly neos

107 Views Asked by At

My Regular expression is not working properly in neos project. Regular expression for DD/MM/YYYY (only 19XX-20XX)

var date_regex = /^(0[1-9]|1\d|2\d|3[01])\/(0[1-9]|1[0-2])\/\/(19|20)\d{2}$/ ;
return date_regex.test(testDate);

I resolved the issue with this

var date_regex = /^(0[1-9]|1\d|2\d|3[01])\/(0[1-9]|1[0-2])\/(19[0-9][0-9]|20[0-9][0-9])$/;

why neos remove the '{2}', Is it any problem with my new Regular expression

Your help would be appreciated

1

There are 1 best solutions below

0
On

In TYPO3 - Fluid template engine the curly brackets are used for view variables so using JavaScript within the view often produces errors as parser cannot guess if this is your Fluid's var or some JS syntax.

You have two solutions, first is to move whole JS into static file and include it in the header as ususally: <script src="/path/to/your/file.js"></script>

Second solution is escaping whole JS with cdata like:

<script>
<![CDATA[

    var date_regex = /^(0[1-9]|1\d|2\d|3[01])\/(0[1-9]|1[0-2])\/\/(19|20)\d{2}$/ ;
    // ....

]]>
</script>