-2

I already have a code, but it's not successfully working. No popup happens when I press submit. Thanks for the assistance in advance

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Email Validation</title>
  </head>
  <body>
  <script>
  function ValidateEmail(mail) 
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value))
  {
    return (true)
  }
    alert("You have entered an invalid email address!")
    return (false)
}
</script>
<table>
<tr>
<td> Email </td>
<td> <input type = 'text' name = 'email' size = '30'  />
</td>
</tr>
  </table>
    <input type="submit" value="Submit" onclick = "ValidateEmail()">
  </body>
</html>
asd afs
  • 3
  • 5
  • It's not a dupe of that - they have the code, they're just having trouble doing something with it – vityavv Mar 15 '18 at 01:12
  • @zevee the question was edited post close vote. However, it needs to be closed as a typo, as it's simply missing the `()` on the method call `ValidateEmail` – Sterling Archer Mar 15 '18 at 01:15
  • 1
    It would be better to ad an event listener, but a simple set of parenthesis will indeed solve the problem. – Obsidian Age Mar 15 '18 at 01:17
  • It's not working, even with the () function. How can you close a duplicate that's simply not working? – asd afs Mar 15 '18 at 01:25
  • The duplicate gives me a different code, that's not helping me learn. I rather used my own code I constructed – asd afs Mar 15 '18 at 01:28
  • I got it, thanks everyone! – asd afs Mar 15 '18 at 01:38
  • Your email is required to have 2 to 3 character top level domain. It no more works in the modern world! – AndreyS Scherbakov Mar 15 '18 at 02:02
  • Please investigate your case further. Whether it's due to the regexp mismatch? If yes, please show us sample EMails those don't satify the expression. Check whether ValidateEmail is called. And then simplify your code into some minimalistic example. – AndreyS Scherbakov Mar 15 '18 at 02:07

1 Answers1

0

onclick="ValidateEmail()" inside of your tag - remember you have to call the function

vityavv
  • 1,482
  • 12
  • 23