mirror of
https://github.com/chylex/.NET-Community-Toolkit.git
synced 2025-04-10 11:15:45 +02:00
Merge branch 'master' of https://github.com/Microsoft/UWPCommunityToolkit into MakeMarkdownUniversalAgain
This commit is contained in:
commit
63e9ba1e65
34
Microsoft.Toolkit/Extensions/StringExtensions.cs
Normal file
34
Microsoft.Toolkit/Extensions/StringExtensions.cs
Normal file
@ -0,0 +1,34 @@
|
||||
// ******************************************************************
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||
// ******************************************************************
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Microsoft.Toolkit.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// All common string extensions should go here
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
internal const string EmailRegex = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether said string is a valid email or not.
|
||||
/// Uses general Email Regex (RFC 5322 Official Standard) from emailregex.com
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> for valid email.<c>false</c> otherwise</returns>
|
||||
public static bool IsEmail(this string str)
|
||||
{
|
||||
return Regex.IsMatch(str, EmailRegex);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user