Check If a Text String Is a Number

To check whether a text string is a number, that is, whether it contains only valid number characters, you can use the following syntax with the IsNumber function:

  • IsNumber(<text value>)

The text value may be a text attribute, text constant or any expression that returns a text constant. Text constants must be in quotation marks (for example, IsNumber("1234")).

The following are accepted as numbers in the text string for the purpose of this function:

  • number characters, such as 1234
  • the decimal point (.), such as 8.56
  • the minus sign (-) indicating a negative number, such as -957
  • a number using E (not case sensitive) for scientific notation, such as 2.5e2
  • a number with trailing F or D (not case sensitive) for float literal and double literal respectively, such as 12.3f

The following non-finite values will return false:

  • NaN (meaning 'not a number')
  • Infinity

Examples of the use of the IsNumber function in rules are given in the following table.

Table 1. Examples of the use of the IsNumber function
Example rule Inputs Outputs

the identification number is valid if

IsNumber(the identification number)

the identification number: 1234578 the identification number is valid = true
the identification number: A1234578 the identification number is valid = false

the postcode is a valid Australian postcode if

IsNumber(the postcode) and

Length(the postcode) = 4

the postcode: 2612 the postcode is a valid Australian postcode = true
the postcode: 75491 the postcode is a valid Australian postcode = false

the temperature is a valid temperature if

IsNumber(the temperature in Celsius)

the temperature in Celsius: 15 the temperature in Celsius = true
the temperature in Celsius: 0.5 the temperature in Celsius = true
the temperature in Celsius: -10 the temperature in Celsius = true

the number is a valid number if

IsNumber(the number)

the number: 12.34F the number is a valid number = true
the number: 567d the number is a valid number = true
the number: 1.2e2 the number is a valid number = true
the number: 1.2e the number is a valid number = false