The following code sample shows how to validate the user input string for minimum, maximum length and check for presence of invalid characters. You can save lot of lines of code by using this class instead of writing several if...else... conditions.
// This code validates string for minimum 2 chars, maximum 3 chars and do not allow characters 'a', 'X', ']', ';' in a string.
try { System.Configuration.StringValidator sv = new System.Configuration.StringValidator(2, 3, "aX];."); sv.Validate("bala.Xml"); } catch (System.ArgumentException ex) { MessageBox.Show(ex.Message); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|