0

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>
0

3 Answers 3

3

Maybe it works

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

0

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

2 Comments

There is no need for this as type=email will validate that it is an email address. The op is trying to validate the email address so it ends with .com
Oh right, then you want the first answer with the "+\.com$"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.