Newbie help: Parsing mobile email address
[1/7] from: kimm2::mcmaster::ca at: 11-Jun-2002 0:43
Hi,
I've managed a crude way to parse a mobile email address down to its
phone number (area code, and 7 digit number) using a loop and if
statements. However, I'm wondering if there's a more efficient way to do
it (shortcuts in REBOL)
Basically I'm trying to do this...
Mobile Email Address: [4165551234--pcs--rogers--com]
<Parsing algorithm>
Result:
~~~~~~~~~~~~~~~~~~~~~~~
Area Code: 416
Phone Number: 5551234
[2/7] from: petr:krenzelok:trz:cz at: 11-Jun-2002 8:09
Matthew Kim wrote:
>Hi,
>I've managed a crude way to parse a mobile email address down to its
<<quoted lines omitted: 8>>
>Area Code: 416
>Phone Number: 5551234
->> Address: [4165551234--pcs--rogers--com]
== [4165551234--pcs--rogers--com]
->> digit: charset [#"0" - #"9"]
== make bitset! #{
000000000000FF03000000000000000000000000000000000000000000000000
}
->> parse to-string address [copy phone some digit "@" copy domain to end]
== true
->> print phone
4165551234
->> print domain
pcs.rogers.com
Parse is fun .... mostly ;-)
Cheers,
-pekr-
[3/7] from: ingo:2b1 at: 11-Jun-2002 8:54
Hi Matthew
Matthew Kim wrote:
<..>
> Basically I'm trying to do this...
> Mobile Email Address: [4165551234--pcs--rogers--com]
<<quoted lines omitted: 3>>
> Area Code: 416
> Phone Number: 5551234
You could use parse ...
>> mea: [4165551234--pcs--rogers--com]
== [4165551234--pcs--rogers--com]
>> parse mea [ copy area 3 skip copy phone to "@" to end ]
== true
>> area
== "416"
>> phone
== "5551234"
This rule would be happy to parse anything with an "@" symbol and at
least 3 characters before it. If you want to check, if this is really a
mobile phone number, you can change it like this:
>> digit: charset [ #"0" - #"9" ]
== make bitset! #{
000000000000FF03000000000000000000000000000000000000000000000000
}
>> parse mea [ copy area2 3 digit copy phone2 6 8 digit "@" to end ]
== true
>> area2
== "416"
>> phone2
== "5551234"
Now you can be sure, that there are only digits before the "@" and at
least 3 for the area and 6 for the phone number, at most 8 for the phone
number.
I hope that helped,
Ingo
[4/7] from: al:bri:xtra at: 11-Jun-2002 18:45
> I'm wondering if there's a more efficient way to do it (shortcuts in
REBOL)
> Basically I'm trying to do this...
> Mobile Email Address: [4165551234--pcs--rogers--com]
<<quoted lines omitted: 3>>
> Area Code: 416
> Phone Number: 5551234
Digit and Alpha are defined by one of my scripts:
>> Digit
== make bitset! #{
000000000000FF03000000000000000000000000000000000000000000000000
}
>> Alpha
== make bitset! #{
0000000000000000FEFFFF07FEFFFF0700000000000000000000000000000000
}
>> M: [4165551234--pcs--rogers--com]
== [4165551234--pcs--rogers--com]
>> parse M [
[ copy Area_Code 3 digit copy Telephone 7 digit #"@" [
[ some alpha some [#"." some alpha]
[ ]
[ end
[ ]
== true
>> Area_Code
== "416"
>> Telephone
== "5551234"
I hope that helps!
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[5/7] from: belymt:saunalahti:fi at: 11-Jun-2002 12:14
At 18:45 11.6.2002 +1200, you wrote:
> > I'm wondering if there's a more efficient way to do it (shortcuts in
>REBOL)
> >
> > Basically I'm trying to do this...
> >
> > Mobile Email Address: [4165551234--pcs--rogers--com]
As international user, i would like to point out that many countries have
totally different scheme on telephone numbers than USA. So if you put a
checking routine to web form (for example) don't assume all phone numbers
have same length as yours... This has happened with some websites and it's
extremely annonying ... :(
For example here in Finland..
Local numbers are between 5 to 9 digits
Area codes are 2 or 3 digits (from 02 to 019)
International prefix for us is 358 (I think?)
For example: (# represents any number, expect 1st can't be zero, I could
give real working numbers but I'm not sure owners of those phones would
like if i did so :-)
09 ########
014 ######
When giving these to foreign people country code is added and Zero dropped.
358 9 ########
358 14 ######
So it can be anything between 8 to 12 digits, and you can't tell area code
apart without knowing local system.
And above does not take mobile numbers into account (those usually have two
digit area code 04, then 1-2 digit Operator code, then 5-8 numbers)
Joanna
[6/7] from: kimm2:mcmaster:ca at: 11-Jun-2002 11:05
Thanks for your help everyone! All these solutions are great!
Joanna, that's a very good point about international numbers. However
at this point I can get away with not worrying about it... whew! It
definitely sounds a lot more complicated.
Cheers,
Matt
[7/7] from: belymt:saunalahti:fi at: 12-Jun-2002 13:11
At 11:05 11.6.2002 -0400, you wrote:
>Thanks for your help everyone! All these solutions are great!
>
>Joanna, that's a very good point about international numbers. However
>at this point I can get away with not worrying about it... whew! It
>definitely sounds a lot more complicated.
Well.. as long as you keep accepting different length numbers it's not a
problem. Country codes are all you may want to try parse
out.. http://www.the-acr.com/codes/cntryno.htm seems to have quite good
list, although I have no idea if it's accurate or up-to-date.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted