jquery username validation not working
<p>Hello i am trying to code user validation script for my website but i something is not right cuz its not working properly </p>

<p>:my code 
jscript :</p>

<pre><code>$(document).ready(function() {
    $('input[name*="username"]').keyup(validateuser);
});

function validateuser() {
    var username = $('input[name="username"]').val();

    if(username == ""){
        $('input[name="username"]').attr('id', 'invalid');
    } else {
        $('input[name="username"]').validate({
        submitHandler: function(form) {
            $('input[name="username"]').attr('id', 'valid');
        }
    });
    }
}
</code></pre>

<p>and a html input form : </p>

<pre><code>&lt;input type="text" name="username" pattern="[A-Za-z0-9\w]{4,20}"&gt;&lt;br&gt;
</code></pre>

<p>so all this script have to do is to set a id to input if its valid or if its not and change border color to red or green , so at first if i clear the field and its empty i got red border but if i write something its still stays red and no changes at all , so probably the the second part of code are not working just not sure why , if someone could help me to solve this would be really nice </p>