Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Email Validation
 
  chubbard posted this script:
  I wrote this quickly for my own purposes.  It will allow blank emails to pass, but will check non-blank emails to validate:
1) contains only a-z, A-Z, _, ., @
2) must contain [x+]@[x+].[xx+]



function validateEmail(szTable, szField, szEmail)
{
    if (szEmail != "") {
        var length = strEmail.length;
        for(var i=0; i < length; i++) {
            var c = szEmail.charAt(i);
            if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '.' || c == '\@')) {
                 Response.addFieldError(szTable, szField, "Email can contain only the characters a-z, A-Z, underscore (_), dot (.), and ampersand (\@)");
            }
        }
        if (!Response.hasFieldErrors()) {
            var atsign = szEmail.indexOf('@');
            var lastdot = szEmail.lastIndexOf('.');
            if ((atsign == -1) || (atsign >= (lastdot - 1)) || (lastdot >= (length - 2))) {
                Response.addFieldError(szTable, szField, "Badly formatted email.");
            }
        }
    }
}
 
  on 2001-10-03 10:04:36, chubbard responded:
  You can also use:

if (record.Email != "" && Members.isValidEmail(record.Email))
    {
    response.addField("MyTable", "Email", "Please enter a valid email address.");
    response.setReshow();
    return false;
    }

Members.isValidEmail() uses the W3C spec for valid email aliases, and so will not fail on a number of valid cases which it looks like your code does fail.

See:

http://helpv2.westside.com/default.view?Topic=Members.isValidEmail
 
  on 2001-10-03 10:11:49, chubbard responded:
  Cool!

Missed that one.
Ignore (or, Westside, delete) this submission.

- Sim
 
  on 2001-10-03 10:25:22, chubbard responded:
  Sims code is an excellent example of field validation. You can easily use it as a template for more specific validation efforts.  
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us