I'm trying to validate a form field for a college exercise, but I'm not succeeding. I do not understand clearly where is the error. Can someone tell me where is the error and why? I do not need the code to copy and paste. I need to understand what is wrong. The function checkUsername(valor) appears as it in the test document.
I appreciate any help.
<input type="text"
class="input" id="username" name="username"
placeholder="nombre de usuario" required />
function checkUsername(valor){
valor = document.getElementById('username').value;
if (/^[a-zA-Z0-9\_\-]{4,30}$/g.test(valor)){
return true;
} else {
return false;
}
}