diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj index e6d84d7..7732333 100644 --- a/LoggingClient/LoggingClient/LoggingClient.csproj +++ b/LoggingClient/LoggingClient/LoggingClient.csproj @@ -117,7 +117,11 @@ + + + + diff --git a/LoggingClient/LoggingClient/Validators/CustomerNumberValidationRule.cs b/LoggingClient/LoggingClient/Validators/CustomerNumberValidationRule.cs new file mode 100644 index 0000000..33b87f2 --- /dev/null +++ b/LoggingClient/LoggingClient/Validators/CustomerNumberValidationRule.cs @@ -0,0 +1,32 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace LoggingClient.Validators +{ + public class CustomerNumberValidationRule : ValidationRule + { + public string ErrorMessage { get; set; } + + /// + /// Regex for Address Number Validation. + /// Beginning with CU following a 5 digit number. + /// + /// + /// + /// + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + Regex regex = new Regex(@"^CU[0-9]{5}$"); + Match match = regex.Match(value.ToString()); + if (match == Match.Empty) + { + return new ValidationResult(false, ErrorMessage); + } + else + { + return ValidationResult.ValidResult; + } + } + } +} diff --git a/LoggingClient/LoggingClient/Validators/EmailValidationRule.cs b/LoggingClient/LoggingClient/Validators/EmailValidationRule.cs new file mode 100644 index 0000000..017fc06 --- /dev/null +++ b/LoggingClient/LoggingClient/Validators/EmailValidationRule.cs @@ -0,0 +1,31 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace LoggingClient.Validators +{ + public class EmailValidationRule : ValidationRule + { + public string ErrorMessage { get; set; } + /// + /// Checks an Email Address if it's valid or not + /// Regex doesn't check if the top + subdomains are valid. + /// + /// + /// + /// + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + Regex regex = new Regex(@"\A[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z"); + Match match = regex.Match(value.ToString()); + if (match == Match.Empty) + { + return new ValidationResult(false, ErrorMessage); + } + else + { + return ValidationResult.ValidResult; + } + } + } +} diff --git a/LoggingClient/LoggingClient/Validators/PasswordValidationRule.cs b/LoggingClient/LoggingClient/Validators/PasswordValidationRule.cs new file mode 100644 index 0000000..4ea68c0 --- /dev/null +++ b/LoggingClient/LoggingClient/Validators/PasswordValidationRule.cs @@ -0,0 +1,31 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace LoggingClient.Validators +{ + public class PasswordValidationRule : ValidationRule + { + public string ErrorMessage { get; set; } + /// + /// Regex for password validation + /// 8 - 15 characters. At least 1 upper, 1 lowercase, 1 number and 1 special character. + /// + /// + /// + /// + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + Regex regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,15}$"); + Match match = regex.Match(value.ToString()); + if (match == Match.Empty) + { + return new ValidationResult(false, ErrorMessage); + } + else + { + return ValidationResult.ValidResult; + } + } + } +} diff --git a/LoggingClient/LoggingClient/Validators/UrlValidationRule.cs b/LoggingClient/LoggingClient/Validators/UrlValidationRule.cs new file mode 100644 index 0000000..2172096 --- /dev/null +++ b/LoggingClient/LoggingClient/Validators/UrlValidationRule.cs @@ -0,0 +1,32 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace LoggingClient.Validators +{ + public class UrlValidationRule : ValidationRule + { + public string ErrorMessage { get; set; } + + /// + /// Regex for url Validation. + /// Doesn't check if the url exists. + /// + /// + /// + /// + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + Regex regex = new Regex(@"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"); + Match match = regex.Match(value.ToString()); + if (match == Match.Empty) + { + return new ValidationResult(false, ErrorMessage); + } + else + { + return ValidationResult.ValidResult; + } + } + } +} diff --git a/LoggingClient/LoggingClient/Views/CustomerView.xaml b/LoggingClient/LoggingClient/Views/CustomerView.xaml index 1fc9687..b09a57e 100644 --- a/LoggingClient/LoggingClient/Views/CustomerView.xaml +++ b/LoggingClient/LoggingClient/Views/CustomerView.xaml @@ -63,9 +63,8 @@ - + @@ -75,9 +74,8 @@ - + @@ -111,9 +109,8 @@ - + @@ -122,9 +119,8 @@ - +