JavaScript validation form Could this code be improved? Would you suggest more sophisticated way of doing client-side signup validation? 

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;script&gt;
        function validateForm() {
            var name = document.forms["registrationForm"]["username"].value;
            if (name == null || name == "") {
                alert("Name must be filled out");
                return false;
            }
            var password = document.forms["registrationForm"]["password"].value;
            var repeatPassword = document.forms["registrationForm"]["passwordAgain"].value;
            if (password.length &lt; 8) {
                alert("Password should contain 8 symbols or more");
                return false;
            }
            if (password != repeatPassword) {
                alert("Filled out passwords should match");
                return false;
            }
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h3&gt;SignUp Form&lt;/h3&gt;
&lt;form name="registrationForm" onsubmit="return validateForm()" action="registration" method="post"&gt;
    Email:&lt;input type="text" name="username"/&gt;&lt;br/&gt;&lt;br/&gt;
    Password:&lt;input type="password" name="password"/&gt;&lt;br/&gt;&lt;br/&gt;
    Repeat Password:&lt;input type="password" name="passwordAgain"/&gt;&lt;br/&gt;&lt;br/&gt;
    &lt;input type="submit" value="signup"/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
An alternative is to simply use what HTML has built-in:

&lt;input type="password" required minlength="8"&gt;


will make that input mandatory and enforce a minimum of eight characters. (You can also use these attributes with type="text".) It's no less secure than doing the validation in JavaScript, as you should still validate it server-side anyway. However, it isn't possible to check using HTML attributes that the two password fields are the same.

The :optional and :required CSS pseudo-classes can be used for styling the input based on the required attribute, but you can also use the more general :valid and :invalid pseudo-classes, which will also respond to things like minlength. You can check these pseudo-classes in JavaScript using Element#matches, but you might have to also check for non-standard naming as ${prefix}MatchesSelector.

The only problem with this approach is the browser compatibility: minlength is not supported except by Chrome and Opera, but you can replace it with the pattern attribute which has wider support, along with the required attribute. Except for Safari and IE &lt;10.

More information about &lt;input&gt; is available at MDN and WebPlatform Docs.