Exforsys.com
 

Sponsored Links

 

ASP.NET Tutorials

 
Home Tutorials ASP.NET
 

ASP .NET: Validating User Input with C#

 

Custom Validator

Page 6 of 7


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).




Next Page: Validation Summary Control


Read Next: Using Rich Server Controls with C#



 

 

Comments


debu_2005_abcd said:

  The course material is very helpful
May 25, 2005, 10:04 am

Allan Joey Laluan said:

  :D Good day! I used validators in my web app and running them locally but my problem is when I copy the system in the live environment the validator did not work. Any possible solution? I check the properties of the validator and compare them in all the examples found in the internet but I have the same result. Can you help me in my problem? :'(
September 27, 2006, 6:52 pm

satish singh said:

  this will be really helpful not only for experienced developers but for beginners also.
December 3, 2006, 11:54 pm

toy said:

  how can i get the page to pass thru if its not valid
ie,
id like to be able to write some like this
if (Page.IsPostBack) {
Page.Validate;
if (Page.IsValid) {
do seomthing
}
else {
do something else
}
}

but the something else doesnt work
cuase as soon as it doesnt pass the validators
it never gets past the postback

am i barking up the wrong tree here?

thanks for any help
December 6, 2006, 12:12 pm

SHRADDHA NIGAM said:

  This is really a very helpful n nice article. I really behefited from it and enjoyed it.
;D
March 5, 2007, 6:31 am

Vaibhav Kulkarni said:

  Hi ,
This is vaibhav.
I recently started to learn self .NET. Initially i found it to be harder than j2EE but tnow I realised that its a preety easy. This article helped me alot to know the basic concepts.
April 16, 2007, 12:43 am

cathy said:

  thank you very much, help me solve a tough problem^^
October 26, 2007, 3:54 am

Rajesh.k said:

  I had some doubt in validaton ontrols .. now i got some idea after reaing this article.. thanks for this aticle writer...........
July 11, 2008, 11:49 pm

Jemson Sentillas said:

  Thanks for the nice article..solve my problems..

--jamesbond--
July 16, 2008, 9:06 pm

Aradhita said:

  This is a compact and easy to read n understand material.
This is very very useful for quick review.
Thanksto the writer.
July 28, 2008, 11:31 pm

amogh said:

  how to make owr own regular expressions using the using System.Text.RegularExpressions;
May 25, 2009, 1:35 pm

Rony said:

  hi,
I started .net recently and want to know that how I can apply a validation to a text box so that it can not be leave blank.
what I'm trying is
if (TxtRegNo.Text.ToString() == "")
{

MessageBox.Show("Fill Registration no");
}
It is working but it saves that blank data into the database.
plz give me a solution
September 17, 2009, 10:37 pm

devang.shah3888 said:

  I want to make validation for ASP.NET with C# how can I put it and for 1 time I want to use the validation for all the pages.
September 29, 2009, 2:19 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape