java script phone number help

Discussion in 'Java' started by jeckunion1980, Sep 14, 2013.

  1. jeckunion1980

    jeckunion1980 New Member

    Joined:
    Sep 14, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Could someone please help me write JaveScript code for the following validation

    All characters should be numbers or space

    Divide the text into three parts based on spaces. Let's call them part1, part2, part3. If you can't divide into three parts, report an error.



    If part1 is 0800 or 0508, then part 2 and part 3 should be three characters long. Otherwise, report an error.

    Otherwise, if part1 is 3 characters long, part 2 and part 3 should be 4 characters long each.



    Otherwise, if part 1 is 2 characters long, part 2 must be 3 characters long and part 4 4 characters long.



    Any other situation (except blank) report an error.

    I would like to store as string. If any of the parameters are not met, they make a ALERT that says the reason why (which i will use OnBlur to call the function for)

    the number should be like xxxx xxx xxx
    or xxx xxxx xxxx
    or xx xxx xxxx

    thank you
     
  2. docardlove1980

    docardlove1980 New Member

    Joined:
    Oct 18, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    The question gives you the answer. Do you know the syntax to implement each step.
    Let's take the question step by step.

    ......How are you going the store the phone number? Array of characters a string ?
    ......Choose. All other steps will depend on this decision.

    All characters should be numbers or space
    .... How do you test this? Once determined either display an error or go on.

    Divide the text into three parts based on spaces.
    .......Find the spaces. What happens if you have two spaces in a row.

    Let's call them part1, part2, part3.
    These could be new variables or indexes into the original string.
    .


    If you can't divide into three parts, report an error.



    If part1 is 0800 or 0508, then part 2 and part 3 should be three characters long. Otherwise, report an error.

    ..... Test for the headers. And the test if there is enough characters in each part.

    Otherwise, if part1 is 3 characters long, part 2 and part 3 should be 4 characters long each.

    .... Check for this pattern and report an error if not found.

    Otherwise, if part 1 is 2 characters long, part 2 must be 3 characters long and part 4 4 characters long.



    Any other situation (except blank) report an error.
     
  3. gradientsoftech

    gradientsoftech New Member

    Joined:
    Jun 5, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hanks this post its realy work for me thanks again
     
  4. gradientsoftech

    gradientsoftech New Member

    Joined:
    Jun 5, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i have a question how to use moiuse on load script i used in image but that not display
     
  5. alia123

    alia123 New Member

    Joined:
    Jan 8, 2016
    Messages:
    65
    Likes Received:
    5
    Trophy Points:
    0
  6. sheamus

    sheamus New Member

    Joined:
    Jul 2, 2016
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    astrology
    Location:
    jalandhar
    can you solve my query how to use a mouse on load script
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice