Email ID Validation Using JavaScript Regular Expression

By using the regular expression "/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/" we can validate the email in JavaScript.



Enter Email ID :


Source Code :
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Email ID Validation Using JavaScript Regular Expression.</title> <script language="javascript"> function ValidateEmailID(txtEmailID) { var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; if (txtEmailID.value == "") { txtEmailID.style.border = ""; return true; } else if (filter.test(txtEmailID.value)) { txtEmailID.style.border = ""; return true; } else { txtEmailID.style.borderColor = "red"; return false; } } </script> </head> <body> <form id="form1" runat="server"> <div> Enter Email ID : <input type="text" onkeyup="ValidateEmailID(this);" /> </div> </form> </body> </html>