Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email parser

Status
Not open for further replies.

crackon

Programmer
Jun 17, 2009
26
0
0
I need a bit of script that checks an email off a form to make sure its valid - cant anyone help
 
How this called in a form, i'm no html expert
 
Try this thread for a great email validation routine:

thread216-1509660

As to how to call it, you could do this in many ways:

- onblur, onchange, or onkeypress on the input field
- onsubmit of the form

It really depends on your needs.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
still it requires a parameter so how is it called with the parameter?
 
its this, how do I call it in a form>?

Code:
function validEmailAddress(email) {
    if (typeof(email) != 'string') return false;

    var atIndex = email.lastIndexOf("@");
    if (atIndex == -1) return false;

    var domain = email.substr(atIndex + 1);
    var local = email.substr(0, atIndex);
    var localLen = local.length;
    var domainLen = domain.length;
    if (localLen < 1 || localLen > 64) {
        // local part length exceeded
        return false;
    } else if (domainLen < 1 || domainLen > 255) {
        // domain part length exceeded
        return false;
    } else if (local.charAt(0) == '.' || local.charAt(localLen-1) == '.') {
        // local part starts or ends with '.'
        return false;
    } else if (local.match(new RegExp('\\.\\.'))) {
        // local part has two consecutive dots
        return false;
    } else if (!domain.match(new RegExp('^[A-Za-z0-9\\-\\.]+$'))) {
        // character not valid in domain part
        return false;
    } else if (domain.match(new RegExp('\\.\\.'))) {
        // domain part has two consecutive dots
        return false;
    } else if (!local.replace(/\\\\/g, "").match(new RegExp('^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$'))) {
        // character not valid in local part unless
        // local part is quoted
        if (!local.replace(/\\\\/g, "").match(new RegExp('^"(\\\\"|[^"])+"$'))) {
        return false;
    }
    } else if (!domain.match(new RegExp('[\\S]+\\.[\\S]+'))) {
        // Not part of the RFC, but for our purposes, make sure the domain isn't 'local' (i.e. at least 'x.y', not just 'x')
        return false;
    }

    return true;
}
 
nowt yet, ah does'nt matter not botherin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top