.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Range Validation Rule

Posted By: Asim Sajjad     Posted Date: October 23, 2010    Points: 2   Category :WPF
In this post I will show you one of the rule which is quite often used in applications is the Range validation, To check the range of the input user control so that user can't enter less or more then the minimum and maximum value respectively. In my previous post I have show you how to use the validation rules you can read it if you don't have any idea about the validation rules.This post is the continuity of the previous post.
Let us start with the range validation rule example. The example code for this example is the same as I have used for the previous post I have added new validation rule with the name of the RangeValidation in the ValidationRules folder, where all the validation rules are placed.In the List 1 you can see the complete class for the RangeValidation rule. Here you can see that I have three properties one for the MaximumLength and MinimumLength for checking the maximum values entered in the user input control and to check the minimum value entered by the user in the input control respectively.

View Complete Post

More Related Resource Links

How to set rule only on form validation success InfoPath 2007



I'm a newbie to InfoPath 2007. I am creating a from without code. Is there a way to set a Rule to the Submit Button which will be triggered only in the case of Form validation success ? can we make use of the "Set condition" to setup a expression  in the Rule, for this purpose. Still i have no idea how to come up with an expression for such purpose. Can someone please explain.

Issue with validation using IDataErrorInfo with int range

Hi, I have a textbox which takes only numbers as input. Textbox has binding with int type property. <TextBox Name="TXT_From" Text="{Binding Path=Range, UpdateSourceTrigger=LostFocus,<br/>  ValidatesOnDataErrors=True, Mode=TwoWay}" /> public int Range { get { return (int)GetValue(RangeFromProperty); } set { SetValue(RangeFromProperty, value); } } public static readonly DependencyProperty RangeFromProperty = DependencyProperty.Register("Range", typeof(int), typeof(MyClass)); In IDataErrorInfo I am doing some auto correction of values. public string this[string property] { get { string msg = null; switch (property) { case "Range": if (Range < 0) Range = 1; if (Range > Max) Range = TempMax; break; default: throw new ArgumentException("Unrecognized property: " + property); } return msg; } } Now the issue is when I enter value greater than 2,147,483,647 which is max value for int the IDataErrorInfo member public string this[string property] is not getting called,also it displays red bordered textbox. I want to avoid this validation and dont want restriction on value input. How to achieve this?  

character limit in textbox in range validation

Hey,I am inserting some text in texbox and there is range validation set as minimum as 10 and maximun as 100. But when i run the program, though i insert the text atleast or more than 10 characters, it is showing the error message of this range validation. So I am confused how to set range so that user has to input atleast 10 character minimum ?

Range Validation


i have text in which i want when the user  lose the focus from the textbox...it should get error message saying please enter the number between 1 and 8.

Validation Rule for 3 Datepickers


I need a Validation rule to verify the values of the 3 datepickers.

Like if suppose we have 3 datepickers a ,b,c.

i need to perform validation upon lost focus.


c in between a and b

But in normal validation rules we can just pass the property value of that control invoked.

How do we validate three. >?

Validation rule on fields with calculated values


Using Infopath 2010.

I used the rules wizzard to add a rule to a field that has a calculated value property and I tried eveything to get this to work. Is this rule suppose to work.

Check calculated value field (week1)- validate as error if greater than 7.

Here is the rule:


Week1 > 7      and
Week1 is not blank

Rule Type:


I expected this to work.

Appreciate confirmation that is is suppose to work. 



How to add validation rule programmatically on datagrid column, whose itemsource is datatable?

I want as user ends editing a datagrid cell, a validation rule should be applied on this cell for error checking like whether its value is null or not and in case of null it should display the error on that cell. All this i want to do programmatically not in xaml. Can anybody guide me with an example ?

Regex validation of a range of digits



I need to check if a variable is inside of a range.

E.g. I'll like to check if variable "input" of type Int32 with the value 5 is in the range from 0 to 15.

I've tried with

if (Regex.IsMatch(input.ToString(), "([0-9]|1[0-5])"))


Console.WriteLine("In the Range");


It doesn't work :-(

Can somebody help,

ThanX :-)





Strange behavior when validation type of rule is applied in Infopath


I've designed InfoPath 2010 form which is browser enabled and 2007 compatible.

In one numeric text box, a Validation rule is written such that if user enters anything outside 0-100 range, it'll display an error message.


1. User opens the form and starts filling the controls.

2. User enters a number in this numeric text box and comes out of the textbox.

3. When focus is lost, validation rule gets triggered.

4. Infopath screen flickers (kind of), reposition itself to the original state.

Question 1: Why does it happen like this? This behavior does not happen in case of "Formatting" type of rule, but happens in "Validation" type of rule.

Question 2: Is validation rule a server-side? What about Formatting rule?

Question 3: This is not related to validation rule. When a textbox value is made right-aligned, we do not see the cursor inside textbox while entering the value. Is it the normal behavior? Is there any way to get rid of this?


Server side validation of Fileupload control not working



I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

Integer Validation



I need to make validation for Textbox to allow enter integer stated by 9 or 6 or 5 , and also maximum 8 digits , how to do that ?





ListViewControl - how to group items by their value, for eg. date range



I have a table containing courses, columns are 

Name - "Yoga Classes"

DateStart - "2/23/2010"

DateEnd - "2/24/2010"

I am using ListView Control to bind it, is there a way to display them and group them by Month? 

for eg.


Piano Class (10th Jan 2010 - 11th Jan 2010)
Guitar Class (10th Jan 2010 - 11th Jan 2010)


Yoga Class (15th Feb 2010 - 16th Feb 2010)

Thanks for help.

VS 2010 HTML validation "in CSS" option - where the hell is it?


In VS 2008 there is a very useful feature of background HTML validation - it checks if CSS class name is valid i.e. it exists in one of the linked css files. But VS 2010 Express does not do that any more. And the relevant setting in Options->Text Editor->HTML->Validation->in CSS is not there. Ok, maybe they made it paid for option? VS 2010 Professional? Not there. Or maybe VS 2010 Ultimate? Not a trace.

1. am I blind?

2. they decided it is too convenient to use and removed it?

3. they will "introduce" it in SP1?

What is going on? That one thing made me move back to VS 2008 web developer.


User validation Issue in xlsx file



I am validating user from Login.xlsx file. It was working fine by validating email and password from that file. For testing i got new file same contents of file but added some more user names.

So after that when i validating the user i am getting the following error "Data type mismatch in criteria expression".

But when i replaced the new to old one it is working fine. The contens of both files are the same. So why this kind of error happened.


set messageTemplateResourceName from resource file in Validation appication block.



  I am using Validation application block in my project and want to set validation message from resource file, but not able to do that. I tried giving the path of resource file in messageTemplateResourceType and name of resource in messageTemplateResourceName. But it did not help as I only receive the message if I have set something in messageTemplate even after setting the resource file.

Here is my code:

<validator lowerBound="1" lowerBoundType="Inclusive" upperBound="250"
              upperBoundType="Inclusive" negated="false" messageTemplate=""
              messageTemplateResourceType="Asurion.jCare.Common.Resources.UIResources.PerilTypeAndDetailsSection, Asurion.jCare.Common.Resources, Version=, Culture=neutral, PublicKeyToken=null"
              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.Enterpris

Localize framework message from xml validation error


I need to validate an XML through XSD. I am using XMLReader (with XmlReaderSettings and 

Validation_EventHandler to do it). Depend on users preference, I would like to change the output message generated by  Validation_EventHandler in french or english.

Any idea on how to perform this?





System.DateTime.AddDays: Value to add was out of range.


I'm getting the following error:

[ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value]
   System.DateTime.Add(Double value, Int32 scale) +7657639
   System.DateTime.AddDays(Double value) +19

The line from which this error originates has the following code:

expires = Now.AddDays(30)

It occurs irregularly and irreproducably. The server date/time is correct and set to GMT. I've heard that it could be some curiosity to do with timezones, but that is speculative.

It seems that we're some time from the year 10,000 yet, so I can't understand why adding thirty days to the current time could cause this! Any ideas? Culture settings perhaps?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend