Skip to content

Commit

Permalink
V2.0.11
Browse files Browse the repository at this point in the history
V2.0.11
  • Loading branch information
zzzprojects committed Apr 19, 2017
1 parent 5591617 commit 640673a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Z.Core/System.Byte/System.Math/Byte.Max.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public static Byte Max(this Byte val1, Byte val2)
{
return Math.Max(val1, val2);
}
R
}
28 changes: 28 additions & 0 deletions src/Z.Core/System.String/String.ToValidDateTimeOrNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Description: C# Extension Methods Library to enhances the .NET Framework by adding hundreds of new methods. It drastically increases developers productivity and code readability. Support C# and VB.NET
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

using System;

public static partial class Extensions
{
/// <summary>
/// A string extension method that converts the @this to a valid date time or null.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <returns>@this as a DateTime?</returns>
public static DateTime? ToValidDateTimeOrNull(this string @this)
{
DateTime date;

if (DateTime.TryParse(@this, out date))
{
return date;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public static partial class Extensions
/// <returns>true if valid email, false if not.</returns>
public static bool IsValidEmail(this string obj)
{
return Regex.IsMatch(obj, @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
return Regex.IsMatch(obj, @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z0-9]{1,30})(\]?)$");
}
}
1 change: 1 addition & 0 deletions src/Z.Core/Z.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@
<Compile Include="System.Single\_CoreObject\Single.In.cs" />
<Compile Include="System.Single\_CoreObject\Single.InRange.cs" />
<Compile Include="System.Single\_CoreObject\Single.NotIn.cs" />
<Compile Include="System.String\String.ToValidDateTimeOrNull.cs" />
<Compile Include="System.String\String.Br2Nl.cs" />
<Compile Include="System.String\String.IsPalindrome.cs" />
<Compile Include="System.String\String.IsAnagram.cs" />
Expand Down
41 changes: 41 additions & 0 deletions test/Z.Core.Test/System.String/String.IsValidEmail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Description: C# Extension Methods Library to enhances the .NET Framework by adding hundreds of new methods. It drastically increases developers productivity and code readability. Support C# and VB.NET
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Z.Core.Test
{
[TestClass]
public class System_String_IsValidEmail
{
[TestMethod]
public void IsValidEmail()
{
{
// Type
string @this = "[email protected]";

// Exemples
var result = @this.IsValidEmail(); // return true;

// Unit Test
Assert.IsTrue(result);
}

{
// Type
string @this = "[email protected]";

// Exemples
var result = @this.IsValidEmail(); // return true;

// Unit Test
Assert.IsTrue(result);
}
}
}
}
1 change: 1 addition & 0 deletions test/Z.Core.Test/Z.Core.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="System.Object\Object.Try.cs" />
<Compile Include="System.String\String.IsValidEmail.cs" />
<Compile Include="System.String\String.IsPalindrome.cs" />
<Compile Include="System.String\String.IsAnagram.cs" />
<Compile Include="System.Array\Array.ClearAll.cs" />
Expand Down

0 comments on commit 640673a

Please sign in to comment.