Jump to content

Java script help


kukooi

Recommended Posts

JavaScript - how to validate e-mail --------------------------------------------------------------------------------function Validate_String(string, return_invalid_chars) {valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';invalid_chars = '';if(string == null || string == '')return(true);//For every character on the string. for(index = 0; index < string.length; index++) {char = string.substr(index, 1); //Is it a valid character?if(valid_chars.indexOf(char) == -1) {//If not, is it already on the list of invalid characters?if(invalid_chars.indexOf(char) == -1) {//If it's not, add it.if(invalid_chars == '')invalid_chars += char;elseinvalid_chars += ', ' + char;}}}if(return_invalid_chars == true && invalid_chars != '') {last_comma = invalid_chars.lastIndexOf(',');if(last_comma != -1)invalid_chars = invalid_chars.substr(0, $last_comma) + ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);return(invalid_chars);}elsereturn(invalid_chars == ''); }function Validate_Email_Address(email_address) {//Assumes that valid email addresses consist of user_name@domain.tldat = email_address.indexOf('@');dot = email_address.indexOf('.');if(at == -1 || dot == -1 || dot <= at + 1 ||dot == 0 || dot == email_address.length - 1)return(false);user_name = email_address.substr(0, at);domain_name = email_address.substr(at + 1, email_address.length); if(Validate_String(user_name) === false || Validate_String(domain_name) === false)return(false); return(true);}but it still cant work out... help needed

Link to comment
Share on other sites

Just use a regular expression available from reglib.com, or go and copy/learn from this script (preferably the latter)http://dynamicdrive.com/dynamicindex16/emailvalidate.htm(By the way, that script also uses a regular expression. It just gets it for you. :))

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...