I'm training JavaScript
with HTML
and CSS
and I'm creating a simple web page where I will calculate BMI. My user, besides informing his weight and height, email, phone ..
By JavaScript
I must perform the IMC calculations and validate both the username and the user's E-mail, I have an example that I'm following, but it has a command that I'm not understanding: ONSUBMIT
<section class="userinfo">
<form class="info" action="index.html" method="post" onsubmit="return validateName()">
<ul>
<li><label for="nome">Nome:</label>
<input type="text" name="nome" placeholder="Digite seu nome" id="name" required/></li>
<li><label for="email">E-mail:</label>
<input type="email" name="email" placeholder="Digite seu E-mail" id="email" required></li>
<li><label for="telefone">Telefone:</label>
<input type="tel" name="telefone" placeholder="(xx)xxxxx-xxxx" id="telefone"/></li>
In the field of Form
would not I have to report two onsubmit
? A validateName and another validateEmail?
My second question is about the operation of JavaScript
function validateName(){
var name = document.getElementById('name').value;
var nameValidator = /^[a-záàâãéèêíïóôõöüúçñ' ]{5,}$/i;
if (!nameValidator.test(name)){
alert("Nome invalido")
return false}
}
Does this !if
mean the logical operator não
correct? My doubt is actually in the condition
nameValidator.test (name)
This namevalidator
, would not have to be called: validateName
, what is my function to validate my user name?