Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - [Matrix1] IsNumeric() : Check if a string value is a decimal number

Author
Message
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Jul 2015 22:41
The IsNumeric function returns true if a string contains a decimal number such as 10, 5.5 or 0. It is used to validate data input from the user or external datasources in situations where it is crucial for the value to contain a basic numerical value with no scientific notations, words or empty string. The IsNumeric function is similar to the VB.NET equivalent sharing the same name.

The following strings will return false:

"199,999,999" because comma delimitation has not been implemented.

"Hat" because the string contains a non-numeric character.

"127.0.0.1" because there are more than one points in what is really an IP address.

"120 23" because no delimitation can be used; except for one decimal point or a prefixed minus sign.

"Delete From Database 'Players' Where 1 = 1" because this most certainly is not what the intended use for a piece of numeric input.

"" because this is an empty string

"." because at least one numeral is required

"25." because the point cannot be the last character in the string.

"+323" because a plus sign is not usually required for positive figures; but the use of a plus sign can be implemented if required.


The following strings will return true:

"100" because only numerals are found.

"1.32" because this is a valid floating point decimal number

" 323 " because the space characters are removed from either side of the valid input by the Matrix1 Trim$() function

".25" because this is a valid floating point number which is also a standard decimal value.




Login to post a reply

Server time is: 2024-04-19 16:26:50
Your offset time is: 2024-04-19 16:26:50