sourcegit/src/Views/Validations/GitURL.cs

19 lines
759 B
C#
Raw Normal View History

2021-04-29 05:05:55 -07:00
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"));
}
}
}