0
Phone Number Validater
Phone number is first digit is 1,9 or8 and total numbers are 8. What I create is the following pattern, but it doesn't work: pattern = r'^[198]{1}[0-9]{7}' I need your help.
8 Respostas
0
Pls elaborate on "it doesn't work". Which strings give false negatives or false positives? Better if you can do it in the question itself.
Pls save your code as public in Code Playground and link it in the question.
That said:
1. Why the {1}?
2. You chose correctly to put an anchor in the beginning. What about the ending?
0
Thank you for your replying.
I'm afraid I'm not sure how I can save my code as public.
Give me a second.
This project is the No.91 of Python course, by the way.
0
1. Why the {1}?
I had thought {1} means the first number is 1, 9 or8 in this case.
2. You chose correctly to put an anchor in the beginning. What about the ending?
What's an anchor? Do you mean {7}?
Thank you for your patience.
I'm just a beginner. I'm trying again and again everyday.
0
In Code Playground, when you save your code, the app asks if you want it to be private or public. If you already saved as private, just click on the word "Private", and you can change.
I recommend doing the course on Regular Expressions, also available in SoloLearn. But on the questions:
Anchor is a metacharacter of regular expressions indicating the beginning or end of a string. The caret (^) finds the beginning, while dollar sign ($) finds the end.
When you include a caret, the expression only matches if it's in the beginning. So you assure the [189] does begin the string.
The same works for the dollar sign and the 7 digits. I'll let you finish this thought.
The numbers between curly brackets ({1}, {7}) are multipliers. So <Char>{7} means 7 occurrencies - [0-9]{7} matches 7 digits.
<Char>{1} matches 1 char, what is already achieved with <Char> itself.
0
Thanks, Emerson.
I've just solved it finally!
0
Taka Great! Would you mind sharing the final expression?
0
Like this