string email = "[email protected]"; if (!Regex.IsMatch(email, @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b", RegexOptions.IgnoreCase)) { // email address is invalid }
string userInput = ""; string sanitizedInput = Validator.HtmlEncode(userInput); // sanitizedInput = "<script>alert('hello');</script>"
long creditCardNumber = 1234567890123456; if (!Validator.TryValidateCreditCard(creditCardNumber)) { // credit card number is invalid }In this example, the `TryValidateCreditCard` method is used to validate a credit card number. Overall, the C# Validator provides a wide range of validation and sanitization functions that can be used to ensure that user input is safe and accurate. It is an essential package library for building secure applications in C#.