Numeric Field Validation in SSRS

In my previous article you saw how to validate a date parameter in SSRS parameter validation using custom code.

Now in this article we will see how to validate a numeric parameter value.

Let's start.

Step 1

We need to write VB code to validate the value as numeric. Here's the VB code to validate the numeric value.

  1. Function IsInputNumeric(Number1 As String,Number2 As StringAs String  
  2. Dim RetValue As String  
  3. If (IsNumeric(Number1) and IsNumeric(Number2)) Then   
  4. RetValue="Valid"  
  5. Else  
  6. RetValue="Please Enter Valid Order ID!!"  
  7. End If  
  8. Return RetValue  
  9. End Function  

Function Description

I have written IsInputNumeric functions that accept the two parameters Number1 and Number2, then I use the IsNumeric built-in function of VB to validate each number parameter and return a message accordingly.


In the preceding function I have used two parameters for validation. You can use any number of parameters depending on requirements.

Step 2

Then we need to create one parameter, IsValidNumber, whose datatype should be Text and the visibility of the parameter should be Internal.

Then go to the default values tab and specify a value and then call this function over here.

Step 3

After the preceding step we need to validate both parameters before passing to the dataset. Click on the button and write an expression.

Step 4

Now we need to add a TextBox to the SSRS report design and then go to the TextBox properties window and call the IsvalidNumber parameter in the value expression of the TextBox and then set the visibility of the TextBox.

Step 5

Then preview the SSRS report and test the preceding logic. Here I put a string in both TextBoxes but my query accepts only a numeric value. So this message is for our user.