| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="RegexPatterns.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Text.RegularExpressions; |
| | | 8 | | |
| | | 9 | | namespace MyNet.Text; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Provides common regex patterns for text validation and matching. |
| | | 13 | | /// </summary> |
| | | 14 | | public static partial class RegexPatterns |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets a precompiled regex pattern for validating email addresses. |
| | | 18 | | /// Matches email addresses with a local part, "@" symbol, and domain part. |
| | | 19 | | /// </summary> |
| | 3 | 20 | | public static Regex EmailPattern { get; } = GetEmailRegex(); |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Gets a precompiled regex pattern for validating phone numbers. |
| | | 24 | | /// Matches phone numbers with optional country code, area code, and extension. |
| | | 25 | | /// </summary> |
| | 3 | 26 | | public static Regex PhonePattern { get; } = GetPhoneRegex(); |
| | | 27 | | |
| | | 28 | | [GeneratedRegex(@"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d |
| | | 29 | | private static partial Regex GetEmailRegex(); |
| | | 30 | | |
| | | 31 | | [GeneratedRegex(@"^(\+\s?)?((?<!\+.*)\(\+?\d+([\s\-\.]?\d+)?\)|\d+)([\s\-\.]?(\(\d+([\s\-\.]?\d+)?\)|\d+))*(\s?(x|ex |
| | | 32 | | private static partial Regex GetPhoneRegex(); |
| | | 33 | | } |
| | | 34 | | |