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.
Hey, I'm sharing a link just check this " http://www.w3resource.com/javascript/form/phone-no-validation.php " . Hope you find it relevant Good Luck