How do i validate a textfield on button click with jQuery?
<p>How can i use jQuery to validate if a textbox is not empty and consists of digits, when i click on a button?</p>

<p>This is the code i have so far:</p>

<p>HTML:</p>

<pre><code>&lt;input type="button" name="Tilføj" value="Tilføj" id="add" /&gt;
&lt;input type="text" id="element" name="element" /&gt;
&lt;div id="result"&gt;&lt;/div&gt;
</code></pre>

<p>Javascript:</p>

<pre><code>$(document).ready(function () {

    $("#add").click(function () {

        $("#element").validate({
            rules: {
                element: {
                    required: true,
                    number: true
                }
            },
            errorHandler: function () {
                $("#result").append("error");
            },
            submitHandler: function () {
                $("#result").append("good");
            }

        });

    });
});
</code></pre>

<p>Do i have to use jQuery validation inside a form for it to work?</p>
