3

How can I limit the number of characters and type of characters that can be inputted.

s = input('What is your number)

a number can only be 9 digits so it should be limited to 9 digits and only numbers

x = input('what is your email address)

an email address can contain a minimum of 8 characters and a maximum of 60 characters and also must contain an @ symbol.

How would I go about doing this?

5
  • 2
    You can not limit the input while the user is typing. You will have to take the input, check it and reprompt if it fails the check. Commented Nov 20, 2018 at 3:46
  • How would I got about doing that> Commented Nov 20, 2018 at 3:47
  • check len of s and/or x Commented Nov 20, 2018 at 3:48
  • And how about the number the type of characters? Also, when I get the length what do I do with it? Commented Nov 20, 2018 at 3:49
  • How to do it? You will have to write code. Tell us if you get stuck! Commented Nov 20, 2018 at 3:51

1 Answer 1

2

In fact, my dear friend, you cannot limit input function, but you can achieve what you want by this way:

def isnumber(s):
    if s.isdigit() and len(s) <= 9:
        return True
    else:
        print('you should input number and length less than 9')
        return False

def main():
    s = input('What is your number')
    while not isnumber(s):
        s = input('What is your number')
    print("your number is", s)


if __name__ == "__main__":
    main()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.