How to attach an custom js validation code with a field validation in model

I have a model in which i capture two dates from and to i want to validate on client side so that from < to i wrote a function to validate on server as

public function validateDate($attribute, $params) {

    if (&#33;&#036;this-&gt;hasErrors()) {

        &#036;from = new DateTime(&#036;this-&gt;from);

        &#036;to = new DateTime(&#036;this-&gt;to);

        if (&#33;(&#036;from &lt; &#036;to)) {

            &#036;this-&gt;addError(&#036;attribute, 'Dates are not correct');




and add rule to rule array as

[[‘to’], validateDate],

can some one tell how to add client side code for this. I was going through documentation i found this link is it compulsory to create a new validation class and then add write functions there or is there any why to add js code to model class .

I am wondering how to use clientValidateAttribute() ( in model to generate js code for comparison.