forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringHelper.cs
More file actions
38 lines (34 loc) · 1.41 KB
/
Copy pathStringHelper.cs
File metadata and controls
38 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
namespace L2dotNET.Utility
{
public static class StringHelper
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>Verify if the given name matches with the regular expression pattern.</summary>
/// <param name="name">The name to search for a match.</param>
/// <param name="pattern">The regular expression pattern to match.</param>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
public static bool IsValidName(string name, string pattern)
{
try
{
return new Regex(pattern).IsMatch(name);
}
catch (Exception ex)
{
Log.Error($"Method: {nameof(IsValidName)}. Message: \'{ex.Message}\' (Parameters: \'{nameof(name)}\' = {name}, \'{nameof(pattern)}\' = {pattern})");
}
return false;
}
/// <summary>Verify if the given name matches with the regular expression pattern.</summary>
/// <param name="name">The name to search for a match.</param>
/// <returns>true if the regular expression finds a match; otherwise, false.</returns>
public static bool IsValidPlayerName(string name)
{
return IsValidName(name, "^[A-Za-z0-9]{1,16}$");
}
}
}