[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Email Validation Using JavaScript in ASP

Posted on 2009-06-27
4
Medium Priority
?
251 Views
Last Modified: 2013-11-23
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>*";
	  form.txt_LMFullName.focus();
	  return false;
	}
  
 
    if(!isEmail(form.txt_LMEmailAddress.value))
	{
       err += "- e-mail Addresse\n";
       if(form.txt_LMEmailAddress.value == "") focusField = "email";
     }
       if(err != ""){
	   document.getElementById("EmailAddress").innerHTML = "<font color=#FF0000>*";
       form.txt_LMEmailAddress.focus();
       return false;
       }
  
  
  document.form1.button_Save.disabled=true;
  document.form1.button_Save.value="Done.";
  return true ;
}
//-->
</script>

Open in new window

0
Comment
Question by:SeanNij
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
dlastlee earned 1400 total points
ID: 24728822
I seem to be able to get it to work once I declare err at the beginning of the function:
var err = "";
0
 
LVL 41

Assisted Solution

by:HonorGod
HonorGod earned 600 total points
ID: 24728875
This might help.

The RE is from here: http://xyfer.blogspot.com/2005/01/javascript-regexp-email-validator.html
<html>
<body>
 
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
}
 
</script>
 
</body>
</html>

Open in new window

0
 
LVL 1

Author Closing Comment

by:SeanNij
ID: 31597556
Thanks for that - spilt the points as the dlastlee solution did fix my prob, but HonorGods suggestion really works nicely in my limited javascript coding...so thanks guys!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24753185
You are very welcome.  Thanks for the assist, and the points.

Good luck & have a great day.
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question