sotirios
sotirios

Reputation: 165

why doesn't this simple html code work? (pattern)

could somebody tell me why this simple code doesn't work? I type a random email address with .com at the end and I receive an error that this address doesn't have the right format.

<!DOCTYPE html>
<html>
<body>


<form action="demo_form.asp">
  E-mail: <input type="email" name="email" pattern="\.com$">
  <input type="submit">
</form>

</body>
</html>

Upvotes: 0

Views: 62

Answers (3)

Alex P
Alex P

Reputation: 96

Try this pattern. It will validate only .com emails.

pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.com$"

Upvotes: 1

Elena
Elena

Reputation: 1829

There's a problem with your pattern, try using this instead pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"

Upvotes: 0

GAVD
GAVD

Reputation: 2124

Maybe it works

<form action="demo_form.asp">
E-mail: <input type="email" name="email" pattern="+\.com$">
<input type="submit">
</form>

Upvotes: 3

Related Questions