JavaScript Tutorial/Regular Expressions/EMail
Содержание
Checking an email address - Version 01
<source lang="javascript">
<html> <head> <title>Checking an email address - Version 01</title> <script type="text/javascript" language="javascript">
</script> </head> <body>
This page allows you to enter and check an email address such as asdf@wbex.ru.ru
<form> <button type="Button" onclick="TestGuess()"> Click here to enter email address</button> </form> </body> </html></source>
Checking an email address - Version 02
<source lang="javascript">
<html> <head> <title>Checking an email address - Version 02</title> <script type="text/javascript" language="javascript">
</script> </head> <body>
This page allows you to enter and check an email address such as asdf@wbex.ru,
<form> <button type="Button" onclick="TestGuess()"> Click here to enter email address</button> </form> </body> </html></source>
Use Regular expression to validate the Email
<source lang="javascript">
<html> <head> <title>E-mail Example</title> <script type="text/javascript">
function isValidEmail(sText) { var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/; return reEmail.test(sText); } function validate() { var oInput1 = document.getElementById("txt1"); if (isValidEmail(oInput1.value)) { alert("Valid"); } else { alert("Invalid!"); } }
</script> </head> <body>
E-mail Address: <input type="text" id="txt1" />
<input type="button" value="Validate" onclick="validate()" />
</body> </html></source>