C# .NET - validations

Asked By venkatesh
09-Sep-10 05:34 AM
end of post
  Sagar P replied to venkatesh
09-Sep-10 05:43 AM
In computer science, data validation is the process of ensuring that a program operates on clean, correct and useful data. It uses routines, often called "validation rules" or "check routines", that check for correctness, meaningfulness, and security of data that are input to the system. The rules may be implemented through the automated facilities of a data dictionary, or by the inclusion of explicit application program validation logic.

We have differnt validation controls in ASP.Net;

  • RequiredFieldValidator

  • CompareValidator

  • RangeValidator

  • RegularExpressionValidator

  • CustomValidator

  • ValidationSummary


  • http://www.beansoftware.com/ASP.NET-Tutorials/Validation-In-ASP.NET.aspx

    In windows applciation you can do validation for textboxes on events like; KeyPress, KeyDown, KeyUp etc as per your requirement.... Also you can use ErrorProvider to show error in proper format.....

    http://www.codeproject.com/KB/validation/validationprovider.aspx
      Sreekumar P replied to venkatesh
    09-Sep-10 07:38 AM
    hi,



    Validation Server Control Description
    http://www.w3schools.com/aspnet/control_comparevalidator.asp Compares the value of one input control to the value of another input control or to a fixed value
    http://www.w3schools.com/aspnet/control_customvalidator.asp Allows you to write a method to handle the validation of the value entered
    http://www.w3schools.com/aspnet/control_rangevalidator.asp Checks that the user enters a value that falls between two values
    http://www.w3schools.com/aspnet/control_regularexpvalidator.asp Ensures that the value of an input control matches a specified pattern
    http://www.w3schools.com/aspnet/control_reqfieldvalidator.asp Makes an input control a required field
    http://www.w3schools.com/aspnet/control_validationsummary.asp Displays a report of all validation errors occurred in a Web page

    http://www.codeproject.com/KB/validation/aspnetvalidation.aspx

    http://www.theserverside.net/tt/articles/showarticle.tss?id=Validators

    http://ashishware.com/ASPValid.shtml
    Create New Account
    help
    body > < form id = "form1" runat = "server" > < div id = "content" > < div style = "text-align: left;" > < asp:ValidationSummary ID = "ValidationSummary1" runat = "server" ValidationGroup = "Authorize" / > < br / > < table border = "0" cellpadding = "5" cellspacing = "0" width 500" > < tr > < td > First Name< br / > < asp:TextBox ID = "FirstNameTextBox" runat = "server" > < / asp:TextBox > < asp:RequiredFieldValidator ID = "RequiredFieldValidator1" ControlToValidate = "FirstNameTextBox" runat = "server" ErrorMessage = "First Name is a Required Field" Text = "*" ValidationGroup = "Authorize" > < / asp:RequiredFieldValidator > < asp:RegularExpressionValidator ID = "RegularExpressionValidator1" runat = "server" ControlToValidate = "FirstNameTextBox" ErrorMessage = "Please limit the length of the content entered to 40 characters" ValidationGroup = "Authorize" ValidationExpression = "^[ \ s \ S]{0, 40}$" > *< / asp:RegularExpressionValidator > < / td > < td > Last Name< br / > < asp:TextBox ID = "LastNameTextBox" runat = "server" > < / asp:TextBox > < asp:RequiredFieldValidator ID = "RequiredFieldValidator2" ControlToValidate = "LastNameTextBox" runat = "server" ErrorMessage = "Last Name is a Required Field" Text = "*" ValidationGroup = "Authorize" > < / asp:RequiredFieldValidator > < asp RegularExpressionValidator ID = "RegularExpressionValidator2" runat = "server" ControlToValidate = "LastNameTextBox" ErrorMessage = "Please limit the length of the content entered
    error message according to the error To validate a server control's input using a RegularExpressionValidator • Add a RegularExpressionValidator control to your page. • Set the ControlToValidate property to indicate which control to validate. • Set to define the message to display if the validation fails. The following example shows a RegularExpressionValidator control used to validate a name field. < %@ language = " C#" % > < form id = " form1" runat = " server" > < asp:TextBox ID = " txtName" runat = " server" / > < asp:Button ID = " btnSubmit" runat = " server" Text = " Submit" / > < asp:RegularExpressionValidator ID = " regexpName" runat = " server" ErrorMessage = " This expression does not validate." ControlToValidate = " txtName" ValidationExpression = " ^[a-zA http: / / msdn.microsoft.com / en-us / library / aa479013.aspx Here is a sample of a RegularExpressionValidator control to validate a name field : <form id = "WebForm" method = "post" runat = "server"> <asp:TextBox id = "txtName" runat = "server"> < / asp:TextBox> <asp:RegularExpressionValidator id = "nameRegex"runat = "server" ControlToValidate = "txtName" ValidationExpression = "[a-zA-Z'.`-´ \ s]{1, 40}" ErrorMessage = "Invalid name"> < / asp:regularexpressionvalidator> < / form> How do I validate input in server-side controls: http: / / www.securityguidanceshare.com / wiki Sujit. The RangeValidator Server Control The RangeValidator control is quite similar to that of the CompareValidator control, but it makes sure that the end-user value or selection provided is between
    works fine. so any ideas?? Thanx in advance. Validation controls, which includes the BaseCompareValidator , BaseValidator , CompareValidator , CustomValidator , RangeValidator , RegularExpressionValidator , RequiredFieldValidator , and ValidationSummary control are not compatible with UpdatePanel http: / / weblogs.asp.net / scottgu / archive / 2007 / 01 / 25 config file (just like in the RC release): < tagMapping > < add tagType = "System.Web.UI.WebControls.CompareValidator" mappedTagType = "Sample.Web.UI.Compatibility.CompareValidator, Validators, Version = 1.0.0.0" / > < add tagType = "System.Web.UI.WebControls.CustomValidator" mappedTagType = "Sample.Web.UI.Compatibility.CustomValidator, Validators, Version = 1.0.0.0" / > < add tagType = "System
    use any one or more than one depends upon your need. Validation Server Control Description CompareValidator Compares the value of one input control to the value of another input control or to a fixed value CustomValidator Allows you to write a method to handle the validation of the value entered RangeValidator Checks that the user enters a value that falls between two values RegularExpressionValidator Ensures that the value of an input control matches a specified pattern RequiredFieldValidator Makes an input control a required field ValidationSummary Displays a report of all validation errors occurred in a Web page see this link following links to use validation controls in proper ways. For textbox validation you can use comparevalidator, requiredvalidator according to your requirement. http: / / www.w3schools.com / aspnet / aspnet_refvalidationcontrols.asp http: / / aspnet.4guysfromrolla Are Predefined Validation Tools In The Toolbox. There Are Total Six type Of Validations. 1) RequiredFieldValidator : This Control Is Used For When You Want That User Must Enter Some Value In Number Etc. These Are Compulsory, So You Can Validate These Fields Using This Control. 2) CompareValidator : This Control Is Used For Comparing two Values From The Given By User. E.g
    end sub < / script > < html > < head > < title > Validation Sample< / title > < / head > < body > < form runat = server > < asp:ValidationSummary runat = server headertext = "There were errors on the page:" / > < p > Please enter a User ID and Password:< / p > < table > < tr > < td > < asp:RequiredFieldValidator runat = server controltovalidate = txtName errormessage = "User ID is required." > * < / asp RequiredFieldValidator > < / td > < td > User ID:< / td > < td > < input type = text runat = server id = txtName > < asp:RegularExpressionValidator runat = server display = dynamic controltovalidate = "txtName" errormessage = "ID must be 6-10 letters." validationexpression = "[a-zA-Z]{6, 10}" / > < asp:CustomValidator runat = server controltovalidate = "txtName" errormessage = "ID is already in use." OnServerValidate = "CheckID" / > < / td > < / tr > < tr td > < asp:RequiredFieldValidator runat = server controltovalidate = txtPWord errormessage = "Password is required." > * < / asp:RequiredFieldValidator > < / td > < td > Password:< / td > < td > < input type = password runat = server id = txtPWord > < asp:RegularExpressionValidator runat = server display = dynamic controltovalidate = "txtPWord" errormessage = "Password must contain one of @#$%^&* / ." validationexpression = ".*[@#$%^&* / ].*" / > < asp:RegularExpressionValidator