LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I check if user input is a valid number

I am reading a string and I need to check if the characters in the string are valid. I need to flag an error if the characters are not in the range of 0 - 9.
0 Kudos
Message 1 of 8
(12,060 Views)
How many ways can Labview do this?
This LabView 6.1 example shows three.
Probably the simplest way is to goto the String >> String/Number Conversion palette and use Decimal String to Number. If the offset past number output doesn't equal the string length, the string contained some character other than a decimal digit.
Message 2 of 8
(12,060 Views)
The simplest way is to use a numeric control for user input and then convert it to a string. Is there some reason that you want to use a string input when you only want numeric data entered?
0 Kudos
Message 3 of 8
(12,060 Views)
Under the comparison subpalette there is a component "Decimal Digit?". This will give you a true or false for a decimal strimg character.
Message 4 of 8
(12,060 Views)
I am reading strings from a table. I dont know if there is a way to make the table to accept numbers only.
0 Kudos
Message 5 of 8
(12,060 Views)
Decimal Digit? works on one character or the first character in a string, not on the whole string. So you need to read the string a character at a time. You can use String Subset in a loop or String to Byte Array and then type cast the bytes as characters.
0 Kudos
Message 6 of 8
(12,060 Views)

Super late reply... I too am trying to read numbers from a table/spreadsheet, and this example covers all but one scenario... a blank cell.  

I've attached the same example, with my solution to the issue, added at the bottom. 

If string length == 0 OR offset past number != string length, then it's not all decimal digits or is blank. 

0 Kudos
Message 7 of 8
(3,382 Views)

20 years late...

0 Kudos
Message 8 of 8
(3,065 Views)