Number Only Values

imgres

One of the guys I work with stumbled upon a quick and easy way to use logic to check if a value is not a valid number (non dependant on type). The logic is as follows:

"123" == +"123" // true
"asdf" == +"asdf" // false

Now you can check to see if your variables are numbers even when they come through as strings (eg. from a form)

 

Published
Categorized as news