2
function validaForm(){
function valida_nome (){
var filter = /^([a-zA-Zà-úÀ-Ú0-9]|-|_|\s)+$/ ;
if(!filter.test(document.getElementById("nome").value)){
document.getElementById("nome").placeholder = "Insira o Nome corretamente";
form1.nome.focus();
return false;
}
}
function valida_email (){
var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if(!filter.test(document.getElementById("email").value)){
document.getElementById("email").placeholder = "Insira o email corretamente";
form1.email.focus();
return false;
}
}
function valida_telefone (){
var filter =/^[0-9]{1,}$/;
if(!filter.test(document.getElementById("telefone").value)){
document.getElementById("telefone").placeholder = "Insira o telefone corretamente";
form1.telefone.focus();
return false;
}
}
}
<form name="form1" action="#" method="post">
Nome<input id="nome" type="text" name="nome"><br/>
Email<input id="email" type="text" name="email"><br/>
Telefone<input id="telefone" type="text" name="telefone"><br/>
<input type="submit" value="testar" onclick="return validaForm()¨">
</form>
What is the difficulty you’re facing?
– Guerra
@War the code doesn’t work, and I can’t find the mistake. But the idea is if the user insert letters for example in the phone field would like the message to appear in the placeholder.
– MagicHat