sourcegit/src/Views/Validations/LocalRepositoryName.cs

17 lines
655 B
C#
Raw Normal View History

2021-04-29 05:05:55 -07:00
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Controls;
namespace SourceGit.Views.Validations {
public class LocalRepositoryName : ValidationRule {
private static readonly Regex REG_FORMAT = new Regex(@"^[\w\-]+$");
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
var name = value as string;
if (string.IsNullOrEmpty(name)) return ValidationResult.ValidResult;
if (!REG_FORMAT.IsMatch(name)) return new ValidationResult(false, App.Text("BadLocalName"));
return ValidationResult.ValidResult;
}
}
}