This is the code
<div class="form-group"><input id="name" type="text" placeholder="Name" name="name" ></div> <button type="submit" class="btn btn-primary signupbtn" onclick="check()">Sign Up</button>
`
let first = document.getElementById('name');
function check() {
var pattern = /^[a-zA-Z]+$/;
var res = pattern.test(first.value);
if(first.value != res){
alert('Invalid First Name');
}
}
`
I have tried keeping (first.value = res) and then executing. This time it is giving alert message only when there is correct input but not when wrong input. But as keep (first.value != res) then it is showing error message every time I press the signup button.
Aucun commentaire:
Enregistrer un commentaire