1
votes

I have requirement where password must contain 8 characters, having one capital letter & one numeric or special character. I have written pattern and assigned it to js variable. But when i tried to access that tpl file smarty throws exception for "comma".

var strPattern = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]{8,})$/;

strPattern is js variable.

How should I need to handle it in smarty ?

Error -

( ! ) FATAL ERROR: UNCAUGHT --> SMARTY COMPILER: SYNTAX ERROR IN TEMPLATE "CHANGE_PASSWORD.TPL" ON LINE 72 "VAR STRPATTERN = /^(?=.[0-9])(?=.[A-Z])(?=.[A-Z])([A-ZA-Z0-9]{8,})$/;" - UNEXPECTED ",", EXPECTED ONE OF: "}" <-- THROWN IN C:\WAMP\WWW\MYPROJECT\SMARTY-3.1.18\LIBS\SYSPLUGINS\SMARTY_INTERNAL_TEMPLATECOMPILERBASE.PHP ON LINE 72*

1

1 Answers

2
votes

As it's JavaScript, the solution should be surrounding JavaScript with literal tags:

<script>
{literal}
var strPattern = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]{8,})$/;
// here rest of JavaScript
{/literal}
</script>

However in theory since Smarty 3.1 literal tags should not be necessary.