Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   java script phone number help (http://www.go4expert.com/forums/java-script-phone-help-t29812/)

jeckunion1980 14Sep2013 15:11

java script phone number help
 
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

docardlove1980 18Oct2013 14:17

Re: java script phone number help
 
Quote:

Originally Posted by jeckunion1980 (Post 100033)
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

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.

gradientsoftech 5Jun2014 14:49

Re: java script phone number help
 
hanks this post its realy work for me thanks again

gradientsoftech 9Jun2014 12:25

Re: java script phone number help
 
i have a question how to use moiuse on load script i used in image but that not display


All times are GMT +5.5. The time now is 09:00.