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.