SECOND instance in instr

Discussion in 'ASP General' started by Joey Martin, Jul 7, 2004.

  1. Joey Martin

    Joey Martin Guest

    I have a script that looks for a phone number. I use an instr to see if
    it finds a - for the phone number. I them grab the 3 characters before
    and 4 after for the phone number. Works well, except when someone uses
    the - in the text.

    How can look for the second instance of the - if the right 4 characters
    past the - are not numeric?

    Thanks!



    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Joey Martin, Jul 7, 2004
    #1
    1. Advertising

  2. Joey Martin

    Steven Burn Guest

    Simplest way;

    1. Allow numerics only

    '// Can be done in ASP or client side Javascript/JScript

    2. Check the length

    '// Can be done in either ASP or client side Javascript/JScript

    --

    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!


    "Joey Martin" <> wrote in message
    news:...
    > I have a script that looks for a phone number. I use an instr to see if
    > it finds a - for the phone number. I them grab the 3 characters before
    > and 4 after for the phone number. Works well, except when someone uses
    > the - in the text.
    >
    > How can look for the second instance of the - if the right 4 characters
    > past the - are not numeric?
    >
    > Thanks!
    >
    >
    >
    > *** Sent via Devdex http://www.devdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Steven Burn, Jul 7, 2004
    #2
    1. Advertising

  3. This is going to take you down the road of pulling your hair out, as people
    have all kinds of interesting ways to format phone numbers when given the
    chance. How about, instead of one big free text entry field, you have three
    separate fields, one for area, one for city, and one for the last four
    digits? Then you just check the length/numeric of each of the three parts.
    You don't have to worry about -, (), ., etc. You could make this dynamic if
    you also need to support UK and other country phone formats. When they
    select their country you can use client-side script to change the designated
    phone number. (You might also do something similar for zip/postal codes.)

    --
    http://www.aspfaq.com/
    (Reverse address to reply.)






    "Joey Martin" <> wrote in message
    news:...
    >I have a script that looks for a phone number. I use an instr to see if
    > it finds a - for the phone number. I them grab the 3 characters before
    > and 4 after for the phone number. Works well, except when someone uses
    > the - in the text.
    >
    > How can look for the second instance of the - if the right 4 characters
    > past the - are not numeric?
    >
    > Thanks!
    >
    >
    >
    > *** Sent via Devdex http://www.devdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Aaron [SQL Server MVP], Jul 7, 2004
    #3
  4. Joey Martin

    Joey Martin Guest

    I am parsing existing data so I do not have an option to change the text
    string.

    Some entries will have xxx-xxx-xxxx, some have xxx-xxxx and some have
    text-text.

    I need to be able to ignore anything that is text-text, but bring in the
    rest. I do not need to separate then with area code, just smash it all
    together is fine.



    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Joey Martin, Jul 7, 2004
    #4
  5. Joey Martin

    Evertjan. Guest

    Aaron [SQL Server MVP] wrote on 07 jul 2004 in
    microsoft.public.inetserver.asp.general:
    > You could make this dynamic if
    > you also need to support UK and other country phone formats.


    The OP did not make it clear he was talking statesside numbers.

    ;-}


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jul 7, 2004
    #5
  6. Joey Martin

    Evertjan. Guest

    Joey Martin wrote on 07 jul 2004 in
    microsoft.public.inetserver.asp.general:

    > Some entries will have xxx-xxx-xxxx, some have xxx-xxxx and some have
    > text-text.


    regex match:

    /(\d\d\d-)?\d\d\d-\d\d\d\d/

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jul 7, 2004
    #6
  7. Joey Martin

    Mark Schupp Guest

    phnum = replace(phnum,"-","")
    if not isnumeric(phnum) then phnum=""

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Joey Martin" <> wrote in message
    news:...
    > I am parsing existing data so I do not have an option to change the text
    > string.
    >
    > Some entries will have xxx-xxx-xxxx, some have xxx-xxxx and some have
    > text-text.
    >
    > I need to be able to ignore anything that is text-text, but bring in the
    > rest. I do not need to separate then with area code, just smash it all
    > together is fine.
    >
    >
    >
    > *** Sent via Devdex http://www.devdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Mark Schupp, Jul 7, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kathy Burke
    Replies:
    0
    Views:
    423
    Kathy Burke
    Nov 24, 2003
  2. =?Utf-8?B?cm9kY2hhcg==?=

    InStr test

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 7, 2006, in forum: ASP .Net
    Replies:
    12
    Views:
    636
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 15, 2006
  3. Replies:
    1
    Views:
    3,477
    Victor Bazarov
    Jul 13, 2005
  4. J. Muenchbourg

    InStr, substr, Mid ???

    J. Muenchbourg, Aug 13, 2003, in forum: ASP General
    Replies:
    1
    Views:
    178
  5. Graham Mattingley

    InStr Help

    Graham Mattingley, Nov 10, 2003, in forum: ASP General
    Replies:
    4
    Views:
    166
    Chris Barber
    Nov 10, 2003
Loading...

Share This Page