< Summary

Information
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Matches(...)100%22100%
IsEmailAddress(...)100%11100%
IsPhoneNumber(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/RegexExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="RegexExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Text.RegularExpressions;
 9
 10#pragma warning disable IDE0130 // Namespace does not match folder structure
 11namespace MyNet.Text;
 12#pragma warning restore IDE0130 // Namespace does not match folder structure
 13
 14public static class RegexExtensions
 15{
 16    extension(string? value)
 17    {
 18        /// <summary>
 19        /// Validates a string against the specified regular expression pattern.
 20        /// </summary>
 21        /// <param name="pattern">The regex pattern to match against.</param>
 22        /// <returns><c>true</c> if the string matches the pattern; otherwise, <c>false</c>.</returns>
 23        public bool Matches(Regex pattern)
 24        {
 2425            ArgumentNullException.ThrowIfNull(pattern);
 26
 2127            return !string.IsNullOrEmpty(value) && pattern.Match(value).Length > 0;
 28        }
 29
 30        /// <summary>
 31        /// Determines whether the string is a valid email address. The method validates against a precompiled email pat
 32        /// </summary>
 33        /// <returns><c>true</c> if the string is a valid email address; otherwise, <c>false</c>.</returns>
 634        public bool IsEmailAddress() => value.Matches(RegexPatterns.EmailPattern);
 35
 36        /// <summary>
 37        /// Determines whether the string is a valid phone number. The method validates against a precompiled phone patt
 38        /// </summary>
 39        /// <returns><c>true</c> if the string is a valid phone number; otherwise, <c>false</c>.</returns>
 640        public bool IsPhoneNumber() => value.Matches(RegexPatterns.PhonePattern);
 41    }
 42}
 43