<form> <input required="" pattern="[A-Za-z0-9_-]{4,8}" /> <button type="submit">Зарегаться</button> </form>