sourcegit/src/Views/Validations/GitURL.cs
2021-04-29 20:05:55 +08:00

18 lines
759 B
C#

using System;
using System.Globalization;
using System.Windows.Controls;
namespace SourceGit.Views.Validations {
public class GitURL : ValidationRule {
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
string url = value as string;
bool valid = !string.IsNullOrEmpty(url)
&& (url.StartsWith("http://", StringComparison.Ordinal)
|| url.StartsWith("https://", StringComparison.Ordinal)
|| url.StartsWith("git@", StringComparison.Ordinal)
|| url.StartsWith("file://", StringComparison.Ordinal));
return valid ? ValidationResult.ValidResult : new ValidationResult(false, App.Text("BadRemoteUri"));
}
}
}