-1

I'm working on a Python script for school and I need it to check the input format in order to perform an action.

Let me exemplify:

The script will ask the user for an input that can either be an id number or a registration number, then, if it's an ID number, it will query a specific database for something, and if it's a registration number, it will query a different database for something else.

The ID number format is: XXX.XXX.XXX-XX and the registration number format is: XX.XXX.XXX/XXXX-XX.

Any ideas?

[EDIT]

Ok, so I just realized I don't necessarily need to check if the format is correct, since the registration number has more characters than the ID number. Now, how can I have an if statement check the amount of characters in an input?

John Lisboa
  • 73
  • 1
  • 2
  • 12
  • @astrosyam nothing really, I have no idea how to even get started... I though about using sqlite3 to query both databases at the same time and return only what I want, but that sounds wrong to me lol – John Lisboa Dec 21 '15 at 01:48
  • 3
    As for determining which type of input has been supplied, have you heard of [regular expressions](https://docs.python.org/2/library/re.html)? – Gord Thompson Dec 21 '15 at 01:51

2 Answers2

1

Do you know if those numbers signify anything other than a value within the period separators? You could just process the string conditions if they appear to be in either format, something like:

user_input = input("Please enter complete value: ")
    if user_input[10] == "/": 
        print("reg numer")
        # registration num to table

Then check for number value for the other condition

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
BSS
  • 11
  • 3
  • Ok, so basically, I have two databases, one for information about the registration number and the other for information about the ID number, I want the script to identify wether it's an ID number or a registration number and based on that, query the correct database. – John Lisboa Dec 22 '15 at 08:11
0

So I ended up using the following:

if len(cliente) == 14:
    print "ID"


elif len(cliente) == 18:
    print "Registration"

else:
    print "You entered an incorrect option"

Which worked quite well for what I needed. Thanks :D

John Lisboa
  • 73
  • 1
  • 2
  • 12