Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>-Which attribute does validation plugin uses: name or id?</p> </blockquote> <p><a href="http://docs.jquery.com/Plugins/Validation">As per documentation</a>, the plugin requires that all <code>input</code> fields contain a <code>name</code> <code>attribute</code>. When specifying the <code>rules</code> and <code>messages</code> inside <code>.validate()</code>, you would use the <code>name</code> <code>attribute</code>.</p> <blockquote> <p>-How to add rules and error messages?</p> </blockquote> <p>The <code>min_length</code> rule should <strong>not</strong> contain an underscore. It's <code>minlength</code>. Otherwise, your code looked correct.</p> <p>Simple demo based on your code...</p> <p><strong>jQuery:</strong></p> <pre><code>$(document).ready(function () { $("#account_info").validate({ rules: { phone_number: { required: true }, recipient_name: { required: true, minlength: 6 // &lt;-- removed underscore } }, messages: { phone_number: { required: "this field is required" }, recipient_name: { required: "Enter recipient name", minlength: "Name should be at least {0} characters long" // &lt;-- removed underscore } }, submitHandler: function (form) { // for demo alert('valid form'); // for demo return false; // for demo } }); }); </code></pre> <p><strong>HTML:</strong></p> <pre><code>&lt;form id="account_info"&gt; &lt;input type="text" name="phone_number" /&gt; &lt;br/&gt; &lt;input type="text" name="recipient_name" /&gt; &lt;br/&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p><strong>Working jsFiddle Demo: <a href="http://jsfiddle.net/rfgRL/">http://jsfiddle.net/rfgRL/</a></strong></p> <hr> <p>Also, when using a rule like <code>minlength</code>, your custom message can contain a placeholder, <code>{0}</code>, that inserts your specific rule definition.</p> <pre><code>minlength: 6 </code></pre> <p>with a custom message...</p> <pre><code>minlength: "Name should be at least {0} characters long" </code></pre> <p>will automatically display...</p> <blockquote> <p>Name should be at least 6 characters long</p> </blockquote> <hr> <p>Since you only call <code>.validate()</code> <em>once</em> on DOM ready to only initialize the validation plugin with its options, there is no purpose in assigning it to a variable; it's not being re-used anywhere... at least it shouldn't be.</p> <pre><code>var v = jQuery("#account_info").validate({...}); </code></pre> <p>Would simply be this...</p> <pre><code>jQuery("#account_info").validate({...}); </code></pre> <p>Elsewhere in your code, if you needed to test the <code>form</code> for validity or re-trigger a validity test, <a href="http://docs.jquery.com/Plugins/Validation/valid">use the <code>.valid()</code> method</a>. It will both return a boolean and trigger display of any pending form errors. Example:</p> <pre><code>if (jQuery("#account_info").valid()) { ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload