Language: C#
Using RegexStringValidator
1: using System; 2: using System.Configuration; 3: 4: namespace Microsoft.Samples.AspNet.Validators 5: { 6: class UsingRegexStringValidator 7: { 8: static void Main(string[] args) 9: { 10: // Display title. 11: Console.WriteLine("ASP.NET Validators"); 12: Console.WriteLine(); 13: 14: // Create RegexString and Validator. 15: string testString = "someone@example.com"; 16: string regexString = @"^[a-zA-Z\.\-_]+@([a-zA-Z\.\-_]+\.)+[a-zA-Z]{2,4}$"; 17: 18: RegexStringValidator myRegexValidator = new RegexStringValidator(regexString); 19: 20: // Determine if the object to validate can be validated. 21: Console.WriteLine("CanValidate: {0}", 22: myRegexValidator.CanValidate(testString.GetType())); 23: 24: try 25: { 26: // Attempt validation. 27: myRegexValidator.Validate(testString); 28: Console.WriteLine("Validated."); 29: } 30: catch (ArgumentException e) 31: { 32: // Validation failed. 33: Console.WriteLine("Error: {0}", e.Message.ToString()); 34: } 35: 36: // Display and wait 37: Console.ReadLine(); 38: } 39: } 40: }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

