L
lotug
I need Regex to indentify 3108222400 phone number.
I need Regex to indentify 3108222400 phone number.
lotug said:I need Regex to indentify 3108222400 phone number.
KT> Now what did you really want to ask? Do you need to recognize
KT> international numbers, or just numbers within the NANP? Is the area
KT> code required? Can the area code be surrounded by parentheses? Can
KT> you have spaces between digits? Hyphens? Periods? Can non-digit
KT> characters, if any, be placed arbitrarily, or must they reflect
KT> the structure of the number? Is a leading "1" allowed? What about
KT> "+1"? What about extensions? What about textual representations
KT> like 1-800-FLOWERS?
if ( m{\QNow what did you really want to ask? Do you need to recognize
international numbers, or just numbers within the NANP? Is the area
code required? Can the area code be surrounded by parentheses? Can
you have spaces between digits? Hyphens? Periods? Can non-digit
characters, if any, be placed arbitrarily, or must they reflect
the structure of the number? Is a leading "1" allowed? What about
"+1"? What about extensions? What about textual representations
like 1-800-FLOWERS?} )
print "Yes, it has phone number like attributes\n" ;
![]()
I need Regex to indentify 3108222400 phone number.
You could try:
if ($_ =~ /3108222400/) {
.
.
.
}
or did you have something else in mind?
Justin.
lotug> I need Regex to indentify 3108222400 phone number.
One of my favorite job interview questions, as an interviewer, goes
something like this:
We have a text-input field that we ask the user to type a
telephone number into. As part of data validation, we need to
know if it's a valid phone number and to identify the area
code. Please write some code to do that.
Now, yes, in the real world this is a hard problem, but I want to see
how the candidate thinks. Within 10 minutes after asking this question
and handing the candidate the whiteboard marker, I have a solid
impression.
(And some of that impression comes from the questions the candidate
asks, because the specification is vague. "US phone numbers only?" is a
very good question. "You must do this a lot - do you have a library
for it already?" is another very good question.)
It's almost embarrassing how many times I've had to stop a candidate
after 20 minutes of hinting and nudging and say, "Okay, there are
several ways to do this, but here's the regex solution" just so we can
move on with the interview - but at that point it's pretty much over
anyway.
Charlton said:We have a text-input field that we ask the user to type a
telephone number into. As part of data validation, we need to
know if it's a valid phone number and to identify the area
code. Please write some code to do that.
You'd think that - but in practice, there are a lot of people who
present themselves as Perl experts convincingly enough to get past HR
people and generalist recruiters.
If you don't have basic Perl knowledge
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.