Consider:
<input id="groupidtext" type="text" style="width: 100px;" maxlength="6" /></td>
Is there a way to set the minimum length to 6?
This question is related to
javascript
jquery
html
You can't set a minimum length on a text field. Otherwise, users wouldn't be able to type in the first five characters.
Your best bet is to validate the input when the form is submitted to ensure that the length is six.
maxlength is not a validation attribute. It is designed to prevent the user from physically typing in more than six characters. The corresponding minlengh is not in scope of the HTML specification, because its implementation would render the textbox unusable.
You can use the HTML5 pattern attribute or use JavaScript.
The pattern could look for example like this:
<input id="groupidtext" type="text" pattern="(.){6,6}" style="width: 100px;" maxlength="6" />
But the pattern attribute will only work with HTML5 browsers. For old browsers you'll need JavaScript.
As suggested in the comments to add, this will only work as soon as a form is about to be submitted. If this input is not in a form and you need validation as a user types, use JavaScript.
Addition to Alex' answer:
$(function() {
$('input[type="submit"]').prop('disabled', true);
$('#check').on('input', function(e) {
if(this.value.length === 6) {
$('input[type="submit"]').prop('disabled', false);
} else {
$('input[type="submit"]').prop('disabled', true);
}
});
});
<input type="text" maxlength="6" id="check" data-minlength="6" /><br />
<input type="submit" value="send" />
But: You should always remember to validate the user input on the server side again. The user could modify the local HTML or disable JavaScript.
You can find the answer here: Is there a minlength validation attribute in HTML5?
Therefore this should do the job:
<input pattern=".{6,6}">
Source: Stackoverflow.com