When developing the administrative part of a module, it is often necessary to limit text field for the number of characters entered. To indicate the maximum length you can use the attribute of the tag input maxlength. Also you can use the rules of the object Validator:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
['validate-length', 'Text length does not satisfy specified text range.', function (v, elm) { var reMax = new RegExp(/^maximum-length-[0-9]+$/); var reMin = new RegExp(/^minimum-length-[0-9]+$/); var result = true; $w(elm.className).each(function(name, index) { if (name.match(reMax) && result) { var length = name.split('-')[2]; result = (v.length <= length); } if (name.match(reMin) && result && !Validation.get('IsEmpty').test(v)) { var length = name.split('-')[2]; result = (v.length >= length); } }); return result; }], |
Example:
1 |
class="required-entry validate-length maximum-length-10 minimum-length-1" |
The rule requires mandatory input and data length from 1 to 10 characters.
If the rule is observed, the following message appears:
Text length does not satisfy specified text range.
Which does not have indication for the allowed text range, therefore, for this filed it is necessary to add a hint indicating the borders.
Partner With Us
Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote.
Talk to Vlad
You are welcome, Saroop. Subscribe to the blog to stay tuned! :)
Its really great help. Thank you very much. Issue resolved.