python regex limit parenthesis to one time

python regex limit parenthesis to one time

I have a problem in Python where program has to check whether or not user enters a phone number in valid format such as:&nbsp;<code>(111)-111-1111</code>&nbsp;I got this program to work using Python regex&nbsp;<code>re.findall</code>function, however, later on I realized that program lets user to enter as many parentheses as he wants, for example:&nbsp;<code>(((((111)-111-1111</code>&nbsp;and this would still go trough the program as a valid format. Question. Is there a way to limit the number of parentheses to the way the format would be as&nbsp;<code>(111)-111-1111</code>? My code is as follows:

I have a problem in Python where program has to check whether or not user enters a phone number in valid format such as: (111)-111-1111 I got this program to work using Python regex re.findallfunction, however, later on I realized that program lets user to enter as many parentheses as he wants, for example: (((((111)-111-1111 and this would still go trough the program as a valid format. Question. Is there a way to limit the number of parentheses to the way the format would be as (111)-111-1111? My code is as follows:

import re
number=input("Please enter phone number:  " )                    
x=re.findall('([(+*)]\d{3}[(+*)][a-]\d{3}[a-]\d{4})', number)
if (x):
    print("Perfect! Your format is valid: -->  " "'"+number+"'")
else:
    print("Not a valid format, please enter as (###)-###-####")


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

An Introduction to Regex in Python

An Introduction to Regex in Python

The Ultimate Guide to Regex (Regular Expressions) in Python

In this Python tutorial, we’ll learning about Regex (Regular Expressions) in Python. Learn how Python regex works, and be able to use the basic patterns and functions in Python’s regex module, re, for to analyze text strings.