This is a discussion on "[SOLVED] using isnan()" within the JavaScript Forum section. This forum, and the thread "[SOLVED] using isnan() are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] using isnan()
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Hi,
so yet more problems for me with javascript!! What I am attempting to do is create a phone number validator which checks; 1.If there is nothing entered into the field return with an alert. 2.If there are any spaces within the text entered into the field, delete them. 3.After the spaces have been deleted check if the entered data is a number using isnan(), and check that the number is no shorter than 11 digits. Then return true! - if the number is shorter than 11 digits return with a alert message. Number 1 isnt a problem, but to be honest I dont have clue how to do numbers 2 and 3. Anyone had any experience doing this before and if so how should i fix it??
Last edited by eon201; Oct 25th, 2007 at 11:53. |
|
|
|
||||
|
Re: using isnan()
Okay, you need to use isNaN, note the capitilisation to check this and normally you need to try get a number out of it.
You could try this simple code
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: using isnan()
wow!
Thats excellent. I am indebted to you. So basically the script now checks if there is any data entered into the field, if not it raises an alert. And if there is any whitespace it is deleted. From this point how can i get the javascript to check that there are 11 digits after deleting the whitespace, and if false raise another alert along the lines of "The number you have entered is to short or to long, please check and try again".?? ps. you've probably noticed im a noob by now! |
|
|||
|
Re: using isnan()
oh. Also where you have used the replace command
document.callmeback_form.telephone.value.replace(/\s/g, "") is there a list on the web of commands to delete certain character types?? eg.letters, or numbers or whitespaces?? Thanks again. Dan. |
|
||||
|
Re: using isnan()
LOL... Everyone's a noon once
You can check the length of a string with .length see below
PS. As for the regular expressions (which is that string you refer to) there are many many many uses for this. Do a google search for Perl Compatible Regex and you will see they are widely discussed and used. Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Last edited by Rakuli; Oct 25th, 2007 at 12:27. |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] 1 solved problem causes another | delusion | Web Page Design | 9 | Dec 21st, 2007 08:12 |
| Adding "Topic Solved" for solved topics | AdRock | Webforumz Suggestions and Feedback | 21 | Oct 4th, 2007 15:08 |