0

I am struggling to validate a simple form and i just cant figure what's wrong. Here is a simple example that doesn't validate:

<form name="loginForm">
  <input type="email" name="email" id="email" required/>
  <input type="submit" value="save" />
</form>
Leo
  • 5,013
  • 1
  • 28
  • 65
aNNgeL0
  • 161
  • 1
  • 2
  • 11

2 Answers2

0

Using the type="email" will validate "a@b" which, of course, is an invalid email address.

You could use a pattern to validate the email address, like so:

<form name="loginForm">
  <input type="email" name="email" id="email" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"/>
  <input type="submit" value="save" />
</form>
Leo
  • 5,013
  • 1
  • 28
  • 65
-1

Your code seems ok. With your code. If you want to test if your form is ok you can add a form action to redirect user after the right submit of your form like this (with action = "newPage.html):

<body>
<form id="loginForm" action="newPage.html">  
    Your mail:
    <input type="email" name="email" id="email" required/>

    <input type="submit" value="Save form" />
</form>

So now to test, you have to create the "newPage.html" file with the body you want:

<body>
   <p>good submit</p>
</body>

If the new page appears, it's ok for your submit!

SarahB
  • 135
  • 1
  • 11