title: Validation with JavaScript on Yii
body: <p>I want to add some JavaScript validation to my form of password creation.</p>
  
  <p>I have the following as javascript</p>
  
  <pre><code>function Validation(){
      var password = document.getElementById('password').value;
      var error = document.getElementById('error');
  
      if((/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]+$/).test(password) == false){
          error.html('error');
      }
  }
  </code></pre>
  
  <p>I have the following code in my _form.php for the user creation </p>
  
  <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'users-form',
      'htmlOptions'=&gt;array('onsubmit'=&gt;'return Validation()'),
      // Please note: When you enable ajax validation, make sure the corresponding
      // controller action is handling ajax validation correctly.
      // There is a call to performAjaxValidation() commented in generated controller code.
      // See class documentation of CActiveForm for details on this.
      'enableAjaxValidation'=&gt;false,
  )); ?&gt;
  
      &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
      &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'username'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'username',array('size'=&gt;20,'maxlength'=&gt;20)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'username'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'password'); ?&gt;
          &lt;?php echo $form-&gt;passwordField($model,'password',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'password'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row buttons"&gt;
          &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
      &lt;/div&gt;
      &lt;div id="error"&gt;
  
      &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>
  
  <p>Now i do have my script imported and even when i put a simple alert('hello') it doesnt work when i press create.</p>
  
  <p>Also i know the validation wont work properly since i am hashing the password. How i can validate it before it becomes hash.</p>