SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Multiple emails validation

    hi there..i need some help on this email validation. i got a text box, can let the users to input many email with the seprator comma(,) or this (. then how can i use the javascxript to do a validation for it? plz help..i duno how to code it. plz help on code.thanx alot

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    First of all, don't rely on javascript to do the validation for you. It's very possible for people to turn off javascript, so make sure that the server validation is the first line of defence, with javascript validation as a second line of defence.

    If you're separating emails with a fullstop then that's going to make it nearly impossible to tell one email from another.

    paul.wilkins@xtra.com.au.jane.wilkins@gmail.com

    Is it paul.wilkins@xtra.com or paul.wilkins@xtra.com.au ??
    Better to use commas instead.

    When you have multiple emails, you can easily separate them into an array with something like the following

    Code Javascript:
    var emails = document.getElementById('emails').split(',');

    Now the emails variable holds an array containing the emails
    All you need to do now is pass them through one of many validation scripts that are out there.

    Code Javascript:
    var validEmails = [];
    for (var i = 0; i < emails.length; i++) {
        if (validateEmail(emails[i]) == true) {
            validEmails.push(emails[i]);
        }
    }

    Just have a look at http://www.google.com/search?q=javas...ail+validation
    to pick and choose from the many validation routines, one of which is sure to fit your needs.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    soli..got some typing error..the seperator should be , OR ;. thanx for help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •