Need Regex for phone number

U

Uri Guttman

RM> What about the many people who have these as they were required
RM> by a former employer? Do they also get to miss out on the
RM> experience of working next to a morbidly obese mouthbreather
RM> that smells of faeces?

you failed the interview. get out of here.

uri
 
U

Uri Guttman

UG> it isn't about knowing phone numbers or styles, it is a basic
UG> simple parsing question that any decent perl hacker should be
UG> able to do.
PJH> The problem is that there are way too many programmers which then take
PJH> their solution to your "toy problem" and apply it to the real world.
PJH> There are a lot of registration forms which require a phone number as a
PJH> mandatory field but don't accept my phone number because it it has too
PJH> few or too many digits or I have formatted it differently than the
PJH> programmer expected (and of course he doesn't tell me what he expects -
PJH> he just tells me "please enter a valid phone number" and deletes the
PJH> other 20 fields I have already entered. There are also forms which don't
PJH> accept email addresses with a "+" in the local part, or punctuation in a
PJH> house number. And so on.

you are missing the point. it is NOT a real world problem. it is just an
exercise given during an interview. it is meant to see HOW the candidate
solves a problem and thinks about it. good questions about formats are a
plus. not even being able to code up a basic simple parser for a basic
number is bad. this thread is crazy. charlton knows the difference
between real world and interview. the OP actually may not. his spec was
left out and he deservedly got a bunch of silly answers. he still never
addressed any real world issues here.

sheesh.

uri
 
T

Ted Zlatanov

TZ> The Brainbench Perl tests are also good at filtering out the rabble.
TZ> It's a commercial service so YMMV but for me it's been helpful.

UG> i dislike them in particular and pretty much any multiple choice
UG> automated test. they don't show how someone thinks or codes. code
UG> review and coding assignments of simple problems are much better
UG> indicators. i actually would downgrade anyone who promoted their
UG> brainbench score.

As I said, YMMV and I'm certainly not advocating it as an alternative to
intelligent questions. My experience has been good using it as a
low-pass filter.

Ted
 
J

Jürgen Exner

Ben Morrow said:
Quoth lotug said:
Yes, I was looking for regex that would identify the phone number in a
txt string regardless of how it was formatted. Different people input
phone numbers in different ways. Also, I have regex that identifies a
phone number in a string, but I'm looking for perl regex that will
identify this particular number within a text string.

3108222400
(310) 822-2400
1(310) 822-2400
1-310-822-2400

For those forms, something like

/1? [-(]? 310 [-)]? \s* 822 -? 2400/x

may be sufficient, though it will catch strings like '-310)8222400'
that you don't want.
Etc., etc.

You will need to make a complete list of all the forms you want to
catch, and create a regex that matches them. Probably the best way is a
simple alternation, which you can build like

my @cases = (
"3108222400",
"(310) 82202400",
"1(310) 822-2400",
"1-310-822-2400",
);

Don't forget formats like
+49 30 314 123456
(030) 314-123456
01149 5772 5871
(05771) 123
Yes, all of these are legitimate and commonly used phone number
patterns, I just changed the actual digits.

jue
 
C

Charlton Wilbur

JS> Nope. As soon as this interviewer told me I failed his test
JS> because I didn't include code to deal with a specification he
JS> had explicitely REMOVED from the question, he failed the
JS> interview.

The original spec:

The instruction was "Substitute well-formed for valid." The result:

If you're going to play nit-picky semantic games, you need to play them
a whole lot better than that.

Charlton
 
J

Jürgen Exner

Charlton Wilbur said:
If you don't have basic Perl knowledge -- and a level of regular
expressions knowledge sufficient to make at least a reasonable attempt
at solving that problem -- then you are unsuited to a position where you
will be expected to program in Perl. Since programming in Perl is a
primary requirement for the positions I'm interviewing candidates for,
assessing whether or not they have a working knowledge of basic to
intermediate Perl is one of my primary goals in the interview.

The problem as stated cannot be solved without massive AI or a large
background list of acceptable phone number formats. There must be
hundreds of commonly used formats. _THAT_ is the real challenge.

Once you have that list then writing an acceptance test for each of them
is the trivial part. into

Now, had you phrased the question differently, e.g. "Assuming you have a
US phone number with 9 or 6 digits, how would you parse it into area
code and number?", now that would be a totally different story.

jue
 
C

Charlton Wilbur

PJH> The problem is that there are way too many programmers which
PJH> then take their solution to your "toy problem" and apply it to
PJH> the real world.

There are. I am not sure why you think this invalidates its use as an
interview question to determine whether a candidate claiming Perl
expertise actually knows rudimentary Perl, which is what I offered it
as.

Charlton
 
C

Charlton Wilbur

TZ> The Brainbench Perl tests are also good at filtering out the
TZ> rabble. It's a commercial service so YMMV but for me it's been
TZ> helpful.

I took the Brainbench C tests some time back, and I was drastically
underimpressed. I'm not sure I'd expect their Perl tests to be
materially better.

Charlton
 
J

Jürgen Exner

Uri Guttman said:
PJH> The problem is that there are way too many programmers which then take
PJH> their solution to your "toy problem" and apply it to the real world.
PJH> There are a lot of registration forms which require a phone number as a
PJH> mandatory field but don't accept my phone number because it it has too
PJH> few or too many digits or I have formatted it differently than the
PJH> programmer expected (and of course he doesn't tell me what he expects -
PJH> he just tells me "please enter a valid phone number" and deletes the
PJH> other 20 fields I have already entered. There are also forms which don't
PJH> accept email addresses with a "+" in the local part, or punctuation in a
PJH> house number. And so on.

you are missing the point. it is NOT a real world problem. it is just an
exercise given during an interview.

And for that purpose insufficient information was provided to the
candidate.
The question is so broad that you need quite some knowledge to even
recognize what information is missing before you can start coding your
REs.

In the form and style the original question was stated this first step
is appropriate for an interview for a Senior International Program
Manager position, not for a developer.

jue
 
J

Jürgen Exner

Charlton Wilbur said:
The answers: We need to make sure we have a reasonable phone number in
order to contact customers. Marketing wants area code information
because it's the key into their demographics information system.

Sorry, there are countries that don't have area codes.
We're
only dealing with North American phone numbers here,

Ahhhhhh, there we go! Finally something you can actually work on.
and we're using
freeform form field entry, so we're dealing with whatever people give
us. If validation fails, we just respond with a "Your phone number was
not understood" message, and ask the user to re-enter it.

Now, this is what I call a reasonable question in an interview for a
programmer position. You _finally_ restricted it enough to make sense.

jue
 
U

Uri Guttman

JS> Nope. As soon as this interviewer told me I failed his test because I
JS> didn't include code to deal with a specification he had explicitely
JS> REMOVED from the question, he failed the interview. You can't hire/not
JS> hire someone who has decided they won't work for you in the first
JS> place.

you failed again. i don't hire people. i place them. i also screen based
on communication skills. you fail there too.

JS> Nope. But if I did do that, and I got caught by an interviewee changing
JS> the requirements in mid-question, and then said he failed because he
JS> didn't do something I said wasn't required anymore, I'd be ashamed to
JS> be doing that job. Yes, it might be fun to toy with people that way,
JS> for a while, but the people that live through that experience aren't
JS> those I'd want to hire.

you don't get it. your loss.

JS> If I did do that job, I'd be much more interested in looking at some
JS> large coding project he wrote than at his one-liners or "golf scores".

and you still don't get it.

use Get::A::Clue ;

uri
 
U

Uri Guttman

PJH> The problem is that there are way too many programmers which then take
PJH> their solution to your "toy problem" and apply it to the real world.
PJH> There are a lot of registration forms which require a phone number as a
PJH> mandatory field but don't accept my phone number because it it has too
PJH> few or too many digits or I have formatted it differently than the
PJH> programmer expected (and of course he doesn't tell me what he expects -
PJH> he just tells me "please enter a valid phone number" and deletes the
PJH> other 20 fields I have already entered. There are also forms which don't
PJH> accept email addresses with a "+" in the local part, or punctuation in a
PJH> house number. And so on.
JE> And for that purpose insufficient information was provided to the
JE> candidate.
JE> The question is so broad that you need quite some knowledge to even
JE> recognize what information is missing before you can start coding your
JE> REs.

JE> In the form and style the original question was stated this first step
JE> is appropriate for an interview for a Senior International Program
JE> Manager position, not for a developer.

come on, you know better than that. it doesn't need more specs. it is a
simple probe of perl skills and problem solving. as has been said before
the ability to know the spec is weak and asking about it is a plus for
the candidate. so it makes for an even better test of how they analyze a
problem.

i am amazed at the analness of those who think this is a bad thing to
do on an interview. wow. i interview dozens of perl hackers a year. i
may know something about this area.

uri
 
B

Bart Lateur

Jürgen Exner said:
And for that purpose insufficient information was provided to the
candidate.
The question is so broad that you need quite some knowledge to even
recognize what information is missing before you can start coding your
REs.

What's worse: I've got the impression that the interviewer doesn't even
*know* what information is missing.
 
C

Charlton Wilbur

UG> i am amazed at the analness of those who think this is a bad
UG> thing to do on an interview. wow. i interview dozens of perl
UG> hackers a year. i may know something about this area.

I'm not amazed, because I've seen candidates make the same response.

If the candidate says, "There are a lot of phone number formats," and I
say, "Right, so limit it to North American formats," that's a good
sign. If the candidate then engages in 20 minutes of bafflegab aimed at
proving to me that I know very little about phone numbers because that's
the topic I chose for a toy problem, well, that gives me an incredible
amount of information that is useful in making hiring decisions.

Charlton
 
U

Uri Guttman

JS> Nope. As soon as this interviewer told me I failed his test because I
JS> didn't include code to deal with a specification he had explicitely
JS> REMOVED from the question, he failed the interview. You can't hire/not
JS> hire someone who has decided they won't work for you in the first
JS> place.
JS> You failed. I wasn't talking about you, I said "this
JS> interviewer". That's Charlton. Topic sentence. It means something.

JS> Yeah. You can't figure out who "this interviewer" refers to and that
JS> means I failed. Sure.

no, i failed you because of your attitude about being interviewed. and
as i place people for my business i have some experience in this
matter. you on the other hand don't.

JS> I don't get a job I wasn't applying for. I'll live.

or other jobs you would want to get. your loss. their gain.

uri
 
C

Charlton Wilbur

UG> or other jobs you would want to get. your loss. their gain.

Indeed. I'd love to see Mr. Stanley's response to some of the requests
I've gotten from our sysadmins or our marketing department.

I'm sure they'd relish being yammered at because they didn't use a
particular term in the idiosyncratic sense he prefers, or because they
used a different term in a clarification and he can't find it in himself
to reconcile the two.

Charlton
 
T

Ted Zlatanov

My personal favorite interview (as an applicant) was at ITA software.
"Sit down, here's a computer. Write a program in 30 minutes to do X.
We'll come back."

My least favorite (as an applicant, again) was with Google:
Him: "What are the 7 OSI layers?"
Me: "You're kidding, right?" (thinking "it's not 1993 again, is it?")

It went downhill from there...

Ted
 
T

thegist

My personal favorite interview (as an applicant) was at ITA software.
"Sit down, here's a computer. Write a program in 30 minutes to do X.
We'll come back."
Was the problem they asked you a toy problem like this phone number
thing, a tricky puzzle, something else?
What did they expect you to do in 30 minutes?
 
P

Peter J. Holzer

UG> it isn't about knowing phone numbers or styles, it is a basic
UG> simple parsing question that any decent perl hacker should be
UG> able to do.

PJH> The problem is that there are way too many programmers which then take
PJH> their solution to your "toy problem" and apply it to the real world.
PJH> There are a lot of registration forms which require a phone number as a
PJH> mandatory field but don't accept my phone number because it it has too
PJH> few or too many digits or I have formatted it differently than the
PJH> programmer expected (and of course he doesn't tell me what he expects -
PJH> he just tells me "please enter a valid phone number" and deletes the
PJH> other 20 fields I have already entered. There are also forms which don't
PJH> accept email addresses with a "+" in the local part, or punctuation in a
PJH> house number. And so on.

you are missing the point. it is NOT a real world problem. it is just an
exercise given during an interview. it is meant to see HOW the candidate
solves a problem and thinks about it.

Right. What we disagree about is what answers we expect. You and Wilbur
expect the interviewee to say "All right, that's easy. A phone number is
always 10 digits and the first three are the area code. Plus there may
be some interpunctation characters (dash, blank, parentheses), so I'll
just hack together a regex for that". I expect the interviewee to say
"That's hard. A phone number could be local, long distance or
international. Both country and area prefixes can be variable length and
there seem to be no generic rules. Plus, those rules change over time,
so even if we get it right now, it's probably wrong next year. So we
have to think about how we can maintain them. And anyway what do you
want with an area code when most people are using cellphones?" Or
something like that. If an interviewee assumes that his local phone
number scheme is all there is and immediately start coding, I'd flunk
him for not thinking things through.

Of course you can always turn it into a simple programming question by
adding restrictions. For example something like this:

We have phone numbers from several sources. We know all of them are
US numbers (or at least they should be), but they are formatted
differently [list of possible formats here or ask the interviewee to
provide one]. We want to get them all into a common format
[description here]. Write a program which converts them all into
this format and writes those which cannot be converted to a
different file for later inspection.

good questions about formats are a plus.

IMO they aren't a plus, they are absolutely required.
not even being able to code up a basic simple parser for a basic
number is bad.

The problem which you refuse to see is that outside of the US there is
no "simple parser for a basic number". And implicitely assuming that
local conventions are universal is a very bad trait in a programmer. The
examples I provided were real, and they were not from the website of a
grocery store somewhere in the midwest - they were from large,
international companies, who apparently employed programmers who
couldn't think beyond their own nose - programmers who would answer
Wilburs question the way you and Wilbur want, but who are utterly
incompetent for their job.
this thread is crazy. charlton knows the difference between real world
and interview.

Maybe he does but I think he filters for the wrong skills. But maybe
he's looking for code monkeys, not programmers.

hp
 
C

Charlton Wilbur

PJH> The problem which you refuse to see is that outside of the US
PJH> there is no "simple parser for a basic number".

I am completely missing how a clarification that says "This is a toy
problem; for its sake we're only interested in US phone numbers" lines
up with refusing to see that there are international phone numbers.

PJH> Maybe he does but I think he filters for the wrong skills. But
PJH> maybe he's looking for code monkeys, not programmers.

The skills necessary to be a competent code monkey are a subset of the
skills necessary to be a good programmer. The last thing my company
needs is more "programmers" who can spout hours of bafflegab but can't
code to save themselves. This question takes five to ten minutes out of
an hour, and very quickly establishes whether the candidate has basic
programming skills.

You don't fail this interview question by pointing out that there are
international phone number formats. You fail by being incapable of
parsing a string to recognize whether or not it contains a recognizable
North American phone number. You fail it by turning it into a pissing
contest about the true meaning of "valid" or "well-formed."

So, Mr. Holzer, put yourself in the interviewer's position. How do you
ascertain whether the candidate has basic Perl knowledge, including
whether he or she is actually the one that wrote any code samples you
may have received?

Charlton
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top