codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  email validation problem  PlzShootMe at 06:17 on Monday, November 08, 2004
 

the only thing that works here is the confirm email, it forces both fields to match, but you can still move to the next field and even submit the form without a valid email address. You can type in one letter and it will still let it go to the next field. Can someone tell me why this script isnt working?

<script language = "javascript" type="text/javascript">
<!--
function validateEmail(addr,man,db) {
if (addr == '' && man) {
if (db) alert('email address is mandatory');
return false;
}
var invalidChars = '\/'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
if (db) alert('email address contains invalid characters');
return false;
}
}
for (i=0; i<addr.length; i++) {
if (addr.charCodeAt(i)>127) {
if (db) alert("email address contains non ascii characters.");
return false;
}
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
if (db) alert('email address must contain an @');
return false;
}
if (atPos == 0) {
if (db) alert('email address must not start with @');
return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
if (db) alert('email address must contain only one @');
return false;
}
if (addr.indexOf('.', atPos) == -1) {
if (db) alert('email address must contain a period in the domain name');
return false;
}
if (addr.indexOf('@.',0) != -1) {
if (db) alert('period must not immediately follow @ in email address');
return false;
}
if (addr.indexOf('.@',0) != -1){
if (db) alert('period must not immediately precede @ in email address');
return false;
}
if (addr.indexOf('..',0) != -1) {
if (db) alert('two periods must not be adjacent in email address');
return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
if (db) alert('invalid primary domain in email address');
return false;
}
return true;
}
-->
</script>


</head>

<label>E-mail address <input name="email" onblur="if (!validateEmail(email,1,1)) {
alert('email address is invalid or was not entered');
return false;} " type="text"></label>

<label>Confirm e-mail address <input name="e_mail2" onchange="if (this.value != this.form.email.value) {alert ('Please confirm your email address.'); this.value = ''; this.focus()}" type="text"></label>

  Re: email validation problem  tgreer at 14:38 on Monday, November 08, 2004
 

Try changing your event handler construction from:

onblur=if (!validateEmail(email,1,1))

To

onblur = "return validateEmail(email1,1,1);"










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  shopping cart
•  File save when generating excel using ASP
•  Re: Menu Problems
•  Re: Help: Trouble with z-Index and SELECT lists
•  Problen encounter when generate excel file using ASP
•  Re: Column count
•  AutoScoll
•  Re: email validation problem
•  Re: database and time date expire


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004