Validate email using a RegEx pattern

Validating Email Addresses is one of the more elusive patterns to define, but this pattern will match 99.99% of all email addresses in actual use today.

A further change you could make is to allow any two-letter country code top level domainĀ and only specific generic top level domains. This regex filters dummy email addresses like asdf@adsf.adsf. You will need to update it as new top-level domains are added.

Example using PHP:

This function will return true/false if the email values passed into it validates against the pattern.

 

Split Mail Address into it’s parts using RegEx pattern

I develop a lot of data parsers and continuously run into composite mailing addresses that require to be split into their meta collections. The following Regex pattern will reformat these two style addresses into XML tag elements.

SAMPLE ADDRESS DATA:

1200 Ocean Rd., Narragansett, RI 02882
1200 Ocean Rd., Narragansett, RI 02882-1234

FIND PATTERN USING REGEX:

REPLACE WITH XML FORMAT:

OUTPUT:

<address>1200 Ocean Rd.</address>
<city>Narragansett</city>
<state>RI</state>
<zip>02882</zip>