1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

regular expressions, regular headache

Discussion in 'Scripting & Programming' started by sirdragon, Mar 18, 2004.

  1. sirdragon

    sirdragon Nibble Poster

    70
    0
    11
    :duel

    Hi guys

    just trying to sort out my javascript CIT 124 assesment, and am stuck on the telephone number field.

    :scrambles

    I can easily get it to validate just on the premise that it only accepts numbers.

    I am trying to get the phone field to accept () ie (01323)234156, but am having problems
    :onthePC
    I have tried with the following 'regular expression' but it is not filtering out the letters, it is set to only include one ' ( ' then any amount of numbers, one ' ) ' then again any amount of numbers.
    :whatthink
    Not sure where i am going wrong here, could possibly be that using the escape sequence with parenthis is incorrect, ie \( as i am not sure if a parenthis has special meaning in regular expressions.

    could you have alook and spot the problem area for me

    [code:1:d888673e4c]re = /^([\(])?\d+([\)])?\d+/ //re is set as a var outside the function[/code:1:d888673e4c]

    :shocked
    //regular expression, / start and end of reg expression, ^ start from begining of string, ([\(\)]) ( )=group, [ ]can have any ONE of whatevers inside \( allow these charcters \back slash is an escape character as ( parenthis is used in regular expressions, ? can be zero or one of the pervious, \d number 0-9,+ one or more times
    :scratch
    [code:1:d888673e4c]
    if (re.test(userdata.tel.value)) //should this be set into negative, how?
    {
    alert("The words Telephone NUMBERS generally indicates a number format :)\neg 01232345435")
    userdata.tel.focus()
    userdata.tel.select()
    return false
    }[/code:1:d888673e4c]



    :morebeer
    cheers martin
     
  2. sirdragon

    sirdragon Nibble Poster

    70
    0
    11
    Hi guys


    got a bit further,,,

    re = /^([\(]?\d+)([\)]?\d)/

    it will now check for and accept ( ) will only accept if at least one number is inside ie. (7).

    I have tried to get it to accept a limiter of 5 characters inside the ()

    re = /^([\(]?\d+ {5} )([\)]?\d)/ but is is not accepting it do not see why??? any ideas!

    How would you get it to not accept any numbers before the ( if there is one??????, at the moment 09(0)000000 is acceptable :cry:

    any ideas

    cheers martin
     
  3. sirdragon

    sirdragon Nibble Poster

    70
    0
    11
    Hi Guys

    do you think I am in the wrong forum for regular expressions????

    which one would you suggest???

    cheers martin
     
  4. SimonV

    SimonV Petabyte Poster Administrator

    6,616
    149
    228
    I think your in the right forum, maybe nobody knows how to help. Javascript is not my area so cant help you. Sorry.
     
    Certifications: MOS Master 2003, CompTIA A+, MCSA:M, MCSE
    WIP: Keeping CF Alive...
  5. Phil
    Honorary Member

    Phil Gigabyte Poster

    1,680
    7
    87
    Hi Martin,

    Sorry you seem to be having a bit of a one sided conversation here. I'm afraid I don't know a great deal about them. I had a look around and found this which may be of some use.
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade
  6. sirdragon

    sirdragon Nibble Poster

    70
    0
    11
    cheers Phil

    will have a looksee

    have u noticed that any location with regular expression somewhere has a mention of ASP think theres a connection ???

    never done any ASP so I have no idea.. :?

    cheers martin
     

Share This Page

Loading...