Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Locate the Design Checker Task Pane in InfoPath 2010
Locate Conditional Formatting and Custom Validation in InfoPath 2010
Conditionally Display Different Values In a Single Expression Box
Create a Button With a Blank Label
Create Shared Rules
5 MOST POPULAR
Access a Method in a Master Page with Code-Behind
Pass Query String Parameters to an ASP.NET Xml Control
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Configure IIS 7 for Custom Error Pages
5 MOST FORGOTTEN
Install Windows 7 Beta onto a Virtual Machine
Group Dates by Year, Month and Day
Configure Lab Color Mode Defaults for Braintrove Articles
Create a Monochromatic Dream Text Effect Using Styles
Combine Multiple Sums Into a Single Function
Microsoft MVP
This article has been viewed 215 times.

Force a Field Value to a Number Using Rules

Page 1 of 2
Written by Gregory Scot Collins
Friday, 20 March 2009, 9:57 AM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
Most secondary data sources use the string data type for all nodes and sadly, custom data validation is not available, as shown in Dialog 1. While you could use code for custom data validation, you might consider using rules to force a value into compliance.
This article will show how to force a field value to a number using rules. It will also show how to restrict the value further, if desired, to be a whole number, a positive number or a negative number.

Force to number

Use the following steps to create a rule to force a field value to a number:
  1. Right-click the field, and then choose Text Box Properties.
  2. In the Text Box Properties dialog box click Rules, and then click Add.
  3. Name the rule Force to Number, and then click Add Action.
  4. Select Set A Field's Value in the Action drop-down list.
  5. Click the Select A Field Or Group button to the right of the Field text box, and then click OK.
  6. Click the Insert Formula button to the right of the Value text box.
  7. In the Formula text box type: translate(number(.), "Na", "").
  8. Click OK three times.
The number function tries to convert the field value to a number. If it fails, the result is NaN, which stands for Not a Number. The translate function converts NaN to an empty string. The result is either a number or a blank value.
The following additional rules can be added if you want to further restrict the value entered to be a a whole number, a positive number or a negative number.

Force to whole number

Use the following steps to create a rule to force a number to be a whole number:
  1. Add another Rule named Force to Number, and then click Set Condition.
  2. Select Contains in the second drop-down list.
  3. Select Type Text in the third drop-down list, and then type: . (i.e. a decimal point).
  4. Click OK, and then click Add Action.
  5. Select Set A Field's Value in the Action drop-down list.
  6. Click the Select A Field Or Group button to the right of the Field text box, and then click OK.
  7. Click the Insert Formula button to the right of the Value text box.
  8. Type one the following in the Formula text box:
    1. If you want to use standard rounding, type: round(.).
    2. If you want to round down, type: floor(.).
    3. If you wnat to round up, type: ceiling(.).
  9. Click OK three times.
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Dialog 1 - Data validation is disabled for fields bound to secondary data source nodes.
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.