'How do I do IF the length of the integer is below a certain value it will prompt error

How do I do IF the length of the integer is below a certain value it will prompt error

sorry if the question is vague but If i want to make it so if the interger is less than 8 numbers, it will tell them to re input



Solution 1:[1]

I'd imagine any reasonable programming language would have the features you need to:

Most likely you'll get the input as a string

Accept the input (as a string)

Test the length of the string and if it's < 8, ask user to re-enter

You might first want to convert the string to an integer and test to see that it's above/below the values you want. Otherwise, the user might enter "00000001" ... 8 digits but a very low value if converted to an integer.

Solution 2:[2]

I am not an experienced person, but in my humble point of view I would:

Assign the user input to a variable, assign its type to integer.

Test the length of the input using built-in functions such as len() in python.

Use exceptions or a conditioned while loop for when the input is < 8, so you can re-iterate the prompt to input the number.

There are many ways to get one thing done. I suggest you experiment with your tools and language of choice, and test your code with numerous types of input so you'd know if there's any other unwanted input that needs to be caught and denied.

best of luck!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve Rindsberg
Solution 2 Wajd