0
Validation using regex
Please I have to make a validation for an input gotten from a user for phone numbers . Please how do I verify that the number starts with 080 or 081 or 090 or 070 Using regular expressions
4 Respuestas
+ 5
esther iyege , i assume that you only care about the first 3 digits that should be 080 or 081 or 090 or 070. I build the pattern the same way: "|" is "or" operator, and "^° defines that the pattern has to match at the beginning of the string. You can continue with the code to check if res list is empty or not. If it is not empty, the number is according your definition.
tel_num = input()
res = re.findall("^080|^081|^090|^070", tel_num)
print(res)
+ 3
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_regex.asp
https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.programiz.com/python-programming/regex&ved=2ahUKEwiqvsbSxaztAhWewjgGHV0SAvQQFjAJegQIEhAB&usg=AOvVaw3F4-ssAMBX8XmlzCwcJFRC&cshid=1606817516771
https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.tutorialspoint.com/python/python_reg_expressions.htm&ved=2ahUKEwiqvsbSxaztAhWewjgGHV0SAvQQFjALegQIBBAB&usg=AOvVaw3I-fhyKm25jL9i1JSWUOGL&cshid=1606817516771
https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.geeksforgeeks.org/regular-expression-python-examples-set-1/amp/&ved=2ahUKEwiqvsbSxaztAhWewjgGHV0SAvQQFjAMegQIFBAB&usg=AOvVaw3r3REzl8pdh_IMwVhnio2u&cf=1&cshid=1606817516771
https://www.google.com/url?sa=t&source=web&rct=j&url=https://realpython.com/regex-python/&ved=2ahUKEwiqvsbSxaztAhWewjgGHV0SAvQQFjAQegQICBAB&usg=AOvVaw0VuOvtMkJOt-3x3VDFrnGU&cshid=1606817516771
+ 2
This live example will help you:
https://code.sololearn.com/cx1tfbykB3pp/?ref=app
+ 1
U can do it by \d*
"d" stands for digits and "*" stands for (zero or more) digits