diegosse diegosse - 1 year ago 67
Python Question

Using regex to check corrections of input

I'm trying to use regex to checking it's the same with input chars.

To be shorter, i'm writing char to the console and i need to check it with pattern. I must write for ex. 123-45-67-890 to go to the next operation. Any ideas?

Answer Source

This should works for pattern you need:

import re
def check (s) : return False if re.match('^\d{3}-\d{2}-\d{2}-\d{3}$', s )==None else True

>>> check ('123-4567-890')
>>> check ('123-45-67-890')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download