Exforsys

Home arrow Technical Training arrow ASP.NET Training

Custom Validator

Page 6 of 7
Author : Exforsys Inc.     Published on: 4th Mar 2005    |   Last Updated on: 18th Dec 2010

ASP .NET: Validating User Input with C#

Ads

Custom Validators can be used to make your own custom validation expressions. You can find many free regular expressions on the website www.Regexlib.com. Here is a small example of the Custom Validator Control.

Sample Code
  1. // This is the server side validation
  2. // Double click the Custom Validator and write this code
  3. {
  4. string strPalindrome = args.Value;
  5. string strReverse = "";
  6. // Reverse the string
  7. for(int intI = strPalindrome.Length -1; intI>=0; intI--) strReverse = strReverse + strPalindrome[intI];
  8. if(strReverse == strPalindrome)
  9. {
  10. args.IsValid = true;
  11. }
  12. else
  13. {
  14. args.IsValid = false;
  15. }
  16. }
Copyright exforsys.com


This validator simply checks that if the string entered is palindrome or not. (Developing and Implementing Web Applications, Kalani).

Ads


 
This tutorial is part of a ASP.NET Training tutorial series. Read it from the beginning and learn yourself.

ASP.NET Training

 

Comments