i have data having emails:
data pattern is like: first_name last_name email
data = foo bar foo@bar.com, foo baz foo@baz.com,foo foo foo@foo.com,bar@bar.com , bar baz bar@baz.com
It may contain spaces. I have to valiadte all the emails by extracting the data.
Note: There may be spaces between words so that spliting by space gives me more some unwanted data …
function validate() {
email_data = data.split(',') // This will get the all data spliting by ','
for (i = 0; i<email_data.length; i++) {
email_new_data = email_data.split(' ') //spliting data by space
// Now I could not find the way to extract emails (only ) from data
}
}
Any suggestion will be helpful.. thanks
The following function split the main
datastring into an array; which then can be parsed withRegExp. As far as I can tell you only want to get the email address; so, we use aRegular Expressionto match an email address. If it matches, you have a valid email. If there’s no match; then basically there’s no valid email on the given segment.Please note that
Regular Expression100% success Email Validation is just impossible; because the RFC is just extremely complicated, check more about here: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.htmlWorking example:
http://jsfiddle.net/kuroir/H7VaT/