Email Regex Pattern API: Validate Email Addresses Correctly

Need a reliable regex pattern for email validation? This guide covers the Email Regex Pattern API, which provides battle-tested patterns for validating email addresses, from simple practical patterns to full RFC 5322 compliance.

The Email Validation Challenge

Email validation is surprisingly complex. A fully RFC-compliant email regex is thousands of characters long, yet even simple patterns work for 99% of real-world cases. The challenge is balancing strictness with practicality.

Valid emails can include unusual characters: "john..doe"@example.com and admin@[192.168.1.1] are technically valid!

Pattern Types

The API provides different pattern types for various needs:

  • Simple: Basic pattern for most common emails
  • Standard: Good balance of accuracy and complexity (recommended)
  • Strict: More comprehensive validation
  • RFC 5322: Full RFC compliance (very complex)
Recommendation: Use the "standard" pattern for most applications. Full RFC compliance is rarely needed and can accept unusual formats users don't expect.

Using the Email Regex API

TinyFn provides pre-built email validation patterns:

API Request
GET https://api.tinyfn.io/v1/regex/patterns/email
Headers: X-API-Key: your-api-key
Response
{
  "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
  "type": "standard",
  "description": "Standard email validation pattern for common use cases",
  "flags": "i",
  "examples": {
    "valid": ["user@example.com", "name.surname@company.co.uk"],
    "invalid": ["invalid", "@example.com", "user@.com"]
  }
}

Parameters

Parameter Type Description
type string Pattern type: simple, standard, strict, rfc5322. Default: standard
anchored boolean Include ^ and $ anchors for full-string match. Default: true

Code Examples

JavaScript / Node.js

// Get the email pattern
const response = await fetch(
  'https://api.tinyfn.io/v1/regex/patterns/email?type=standard',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const { pattern, flags } = await response.json();

// Use it for validation
const emailRegex = new RegExp(pattern, flags);
console.log(emailRegex.test('user@example.com')); // true
console.log(emailRegex.test('invalid-email')); // false

Python

import requests
import re

response = requests.get(
    'https://api.tinyfn.io/v1/regex/patterns/email',
    params={'type': 'strict'},
    headers={'X-API-Key': 'your-api-key'}
)
result = response.json()

# Compile and use the pattern
email_pattern = re.compile(result['pattern'], re.IGNORECASE)
print(bool(email_pattern.match('user@example.com')))  # True
print(bool(email_pattern.match('user@localhost')))  # False (no TLD)

cURL

curl "https://api.tinyfn.io/v1/regex/patterns/email?type=simple" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Form Validation: Validate email inputs before submission
  • Data Cleaning: Filter valid emails from datasets
  • Email Extraction: Find emails in text (use unanchored pattern)
  • Input Masking: Guide users toward valid email format
  • API Validation: Validate email parameters in requests

Best Practices

  1. Don't rely solely on regex: Send a confirmation email for true validation
  2. Allow plus addressing: Patterns should allow user+tag@example.com
  3. Support international TLDs: Modern TLDs can be longer than 3 characters
  4. Trim whitespace: Trim input before validation

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-regex": {
      "url": "https://api.tinyfn.io/mcp/regex/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all regex tools available via MCP in our Regex MCP Tools for AI Agents guide.

Try the Email Regex Pattern API

Get your free API key and start validating emails correctly.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key