Page tree
Skip to end of metadata
Go to start of metadata




Introduced in

Version:3.3

Description

Description:Checks whether the passed string is a valid number.

Syntax

Syntax:[number, allowEmpty, allowDecimal, include, exclude] call fn_vbs_validateNumber
Parameters:
  • number: String or Number - Number to validate.
  • allowEmpty: Boolean - If true, then an empty number string is considered valid. If false, then number cannot be empty (optional, default: false).
  • allowDecimal: Boolean - If true, then a decimal point is allowed in the passed number. If false, then only integers are permitted (optional, default: true).
  • include: Array of Number or Array - List of numbers or ranges which are allowed. A range is specified using a sub-array: [min, max]. The range extremes are included in the allowed numbers, and the string "inf" can be used (in either place) to indicate an "infinite" limit (optional, default: [] - no restrictions).
  • exclude: Array of Number or Array - List of numbers or ranges which are not allowed (same functionality and syntax as include).
Return Value:Number - Validation result. Can be:
  • 0: Number is valid.
  • 1: String was empty, without it being allowed.
  • 2: String does not contain valid number.
  • 3: Number is not within allowed range.
  • 4: Number is in forbidden range.
  • 5: Number contains decimal point, without it being allowed.

Warning

When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.

Examples

Examples:
_chk = ["12.34"] call fn_vbs_validateNumber; // returns 0 (valid number)
_chk = ["12ab"] call fn_vbs_validateNumber; // returns 2 (invalid number)
_chk = ["12.34",true,false] call fn_vbs_validateNumber; // returns 5 (decimal number not allowed)
_chk = [ "3",true,true,[1,3,5] ] call fn_vbs_validateNumber; // returns 0: "3" IS in allowed list [1,3,5]
_chk = [ "3",true,true,[[1,5]] ] call fn_vbs_validateNumber; // returns 0: "3" IS in allowed range 1 to 5
_chk = [ "3",true,true,[[5,"inf"]] ] call fn_vbs_validateNumber; // returns 3: "3" is NOT in allowed range 5 to infinity
_chk = [ "3",true,true,[],[2,4,6] ] call fn_vbs_validateNumber; // returns 0: "3" is NOT is excluded list [2,4,6]
_chk = [ "3",true,true,[],[[1,5]] ] call fn_vbs_validateNumber; // returns 4: "3" IS in excluded range 1 to 5
_chk = [ "3",true,true,[[-5,-3],1,[3,5]] ] call fn_vbs_validateNumber; // returns 0: "3" IS in allowed range -5 to -3, 1, or 3 to 5

Additional Information

See also: fn vbs validateCode, isValidVarName, Engine Scripts Dialog Validator
Multiplayer: 
Problems: 

Notes