70Views3Replies

Author Options:

ARDUINO: how do I check if the inputString has just numbers and not letters?? Answered

I am writing a program, and in the program there is a part where you can change password. Now, I want the program to accept only numbers, and only 4 tabs (Example: 1234, 5678 and more. between 0000 to 9999). how do I do that? what function should I read about? thank you in advance 

Tags:arduino

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
bwrussell
bwrussell

5 years ago

I haven't tried this so it may not work or may be more lines but rather than check each character you might be able to write the input with both chars and ints and then compare the two (if( x == y)). If they are the same then it is all numbers if it is different then there are non number inputs.

The theory is that the int wont hold non numbers so in the case that a character was entered it's value would then differ from a variable holding the raw input.

If you try this be sure to post the results so we can all learn.

0
steveastrouk
steveastrouk

5 years ago

Look to see if the received character is in the ASCII set from '0' to'9', or 48 to 57.

0
iceng
iceng

Answer 5 years ago

+1

Or if you know hex-decimal 30h=0 to 39h=9

So you only need to check the input string for a leading HEX 3n character and you know it is a number.