Email Validation Using JavaScript in ASP

Hi all,

Very very new to ASP and Java. With the help of much reading on EE I have managed to get some validation working for my ASP development. However, in trying to get my Email validation to working using JavaScript and RegEx, it falls apart.

The validiation works for the blank LMFullName but not for the Email Address.

I'm sure its got to do with my JavaScript - help....
<script language="JavaScript" type="text/javascript">
<!-- JavaScript to validate form and disable submit button
function isEmail(strValue){
      var objRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      return objRegExp.test(strValue);
function CheckForm(form)
  document.getElementById("LMFullName").innerHTML = "";
	if (form.txt_LMFullName.value == "")
	  document.getElementById("LMFullName").innerHTML = "<font color=#FF0000>*";
	  return false;
       err += "- e-mail Addresse\n";
       if(form.txt_LMEmailAddress.value == "") focusField = "email";
       if(err != ""){
	   document.getElementById("EmailAddress").innerHTML = "<font color=#FF0000>*";
       return false;
  return true ;

Open in new window

Who is Participating?
dlastleeConnect With a Mentor Commented:
I seem to be able to get it to work once I declare err at the beginning of the function:
var err = "";
HonorGodConnect With a Mentor Commented:
This might help.

The RE is from here:
e-mail <input type='text' onchange='validate(this.value)'>
<script type="text/javascript">
var emailRE = new RegExp( '^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)', 'i' );
function validate( email ) {
  var result =  emailRE.test( email )
  if ( result ) {
    alert( 'ok' );
  } else {
    alert( 'invalid e-mail address' )
  return result

Open in new window

SeanNijAuthor Commented:
Thanks for that - spilt the points as the dlastlee solution did fix my prob, but HonorGods suggestion really works nicely in my limited javascript thanks guys!
You are very welcome.  Thanks for the assist, and the points.

Good luck & have a great day.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.