View Full Version : Email validation with javascript

12-02-2009, 10:32 AM
This are my codes..

var add = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var email = form.txtEmail.value;
if (add.test(email) = false)
alert("Please enter a valid email.");
return false;
return true;

bt it wun work.. pls help..

Jon W
12-02-2009, 12:12 PM
You might have better luck on the client side JavaScript programming forum. As this is the server side (PHP) scripting forum.

12-02-2009, 01:35 PM
Yes indeed. Moving from PHP to Javascript.

Philip M
12-02-2009, 02:31 PM
Here you are:-

<form name= "form1">
<input type = "text" name = "txtEmail" onblur ="chkemail(this)">

<script type = "text/javascript">

function chkemail(which) {
var email = which.value;
if (!/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(email)) {
alert("Please enter a valid email address!");
which.value = "";
myfield = which; // note myfield must be a global variable
setTimeout('myfield.focus();myfield.select();' , 10); // to overcome a bug in Firefox
return false;
return true;


Quizmaster: When counting down, what whole number follows 37?
Contestant: er, 19.