Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several routes you could go here.</p> <ol> <li><p>One continue by writing your validation in this manner</p> <ul> <li><p>You would want your code to probably look something like the following</p> <pre><code>var type = $("input#type").val(); // Check a that a tank type has been entered. if(!/^MR \d{3}$/.test(type)){ $("#error_upload").html("Please enter the tank number in a format MR XXX."); $("#type").css({borderColor:'red'}).focus(); $("name,#file").css({borderColor:'#ccc'}); return false; } </code></pre></li> </ul></li> <li><p>Integrate something like the above into jQuery Validate, since I'm assuming you'll need validation elsewhere</p></li> <li><p>Simplify the entry by allowing only 3 digits and appending on <code>'MR ' + type</code>, since every one of these requires MR and a space, why ask the user to even enter it?</p> <pre><code>var num = $("input#type").val() , type; // Check a that a tank type has been entered. if(!/^\d{3}$/.test(num)){ $("#error_upload").html("Please enter the tank number with only digits."); $("#type").css({borderColor:'red'}).focus(); $("name,#file").css({borderColor:'#ccc'}); return false; } else { type = 'MR ' + num; } </code></pre></li> <li><p>Combine step 2 and 3, which would result on having an input like this <code>&lt;input type="text" class="required digits" maxlength="3" minlength="3" /&gt;</code>. This results in less complex data entry and not having to worry about simple validation logic. This is my favorite choice.</p></li> <li><p>Use a input mask to prevent users from making any mistakes to begin with, but it is the most "intrusive".</p></li> </ol>
 

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