|
|
 | | From: | smilelots4 at yahoo.com | | Subject: | Javascript help | | Date: | 17 Jan 2005 14:52:18 -0800 |
|
|
 | Hello,
I am trying to validate the format of telephone number (xxx-xxxx) This is what i have so far (which also has other validations such as check to see if there are any inputs in the text box-but that script works)
function fncTest() { x=document.UpdateInput set=/^\d{3}-\d{4}$/
if (!x.txtPhone.match(set)){ alert( "Please phone number" ); return false; } }
is there something wrong with my syntax? Please help.... Thank you...
|
|
 | | From: | smilelots4 | | Subject: | Re: Javascript help | | Date: | 19 Jan 2005 15:07:47 -0800 |
|
|
 | Thanks for the tips, but im javascript noob...:) just making it simple. :)
publisher? confused....:p
|
|
 | | From: | smiyos | | Subject: | Re: Javascript help | | Date: | 19 Jan 2005 19:56:12 -0800 |
|
|
 | Thanks for the tips :)
|
|
 | | From: | spinoza1111 at yahoo.com | | Subject: | Re: Javascript help | | Date: | 18 Jan 2005 19:04:51 -0800 |
|
|
 | Dude, once he gets the phone number parsing with your sage advice, we can worry about the fact that the format
(1) Doesn't support area codes which are necessary to make local calls in most USA metro areas owing to the greed of telecom companies in the dot.com era
(2) Doesn't BEGIN to support even local phone numbers in the mysterious, far-off Orient
(3) Even considered as a solution forces the user to enter a dash. I discovered by surveying my students at DeVry that younger people tend to leave out the dash, and here in the mysterious, far-off Orient it is never used. People simply slam in eight digits.
(4) Doesn't support international dialing codes such as are used in the mysterious and far-off Orient to call home for money
Of course, regular expressions can be used to capture all these rules. However, BNF and a simple recursive descent parser is a clearer solution than some explosion in a gnome factory.
globalPhoneNumber := usaPhoneNumber | furrinerPhoneNumber usaPhoneNumber := localPhoneNumber | ldPhoneNumber localPhoneNumber := prefix [sep] suffix prefix := THREE_FRIGGIN_DIGITS sep := BLANK | DASH .. .. .. boolean globalPhoneNumber(string strInstring) { int intIndex1 = 0; return ( ( usaPhoneNumber( strInstring, intIndex1 ) || furrinerPhoneNumber( strInstring, intIndex1 ) ) && intIndex1 = len(strInstring) ) } boolean usaPhoneNumber(string strInstring, ref int intIndex ) { .. .. ..
etc. The BNF, unlike a re, can be used in a PowerPoint presentation to the users. Subjecting actual users, concerned to discover whether you are parsing lead or customer phone numbers, would clear the room if you presented a re, just as clearly as if you'd brought a karaoke boombox and launched into Send In The Clowns.
I hope you are well. Hey, did my publisher ever get back to ya? What did they say?
|
|
 | | From: | smilelots4 | | Subject: | Re: Javascript help | | Date: | 19 Jan 2005 15:05:57 -0800 |
|
|
 | It worked! :) thanks much for the help.... i noticed though, that it still worked without:
frm.txtPhone.focus();
Thanks again! :)
|
|
 | | From: | Programmer Dude | | Subject: | Re: Javascript help | | Date: | Thu, 20 Jan 2005 11:52:56 -0600 |
|
|
 | smilelots4 writes:
> It worked! :) thanks much for the help.... i noticed though, > that it still worked without: > > frm.txtPhone.focus();
Certainly. The .focus() method just sets the "cursor" back in that text box to make the user's life easier. This is especially helpful when validating lots of fields.
> Thanks again! :)
Da nada.
|
|
 | | From: | spinoza1111 at yahoo.com | | Subject: | Re: Javascript help | | Date: | 19 Jan 2005 18:34:05 -0800 |
|
|
 | smilelots4 wrote: > Thanks for the tips, but im javascript noob...:) just making it simple. > :) > > publisher? confused....:p
Sorry, I was talking to Programmer Dude. He and I had a battle *royale* last year, which I won, but during which he sent mail to my publisher complaining about me prior to the publication of my book Build Your Own .Net Language and Compiler.
At a technical level Dude gives good advice.
I understand that the re is fine as long as you're sure that the user wants only the entry of local phone numbers. However, as I said, in major American cities, the area code is necessary.
My book, Build Your Own .Net Language and Compiler, although about VB.Net, does include a regular expression testing laboratory which allows one to test regular expressions in detail since I have seen this as a problem. It may be of some limited use to you but there are differences in regular expressions from one implementation to another.
I suppose you might already have another box for the user to enter area code if he or she so desires. But as an American civilian expatriate in Communist China (:-)) I've occasionally had problems in entering data at American Web sites because of these format differences.
|
|
 | | From: | Randy Howard | | Subject: | Re: Javascript help | | Date: | Sat, 22 Jan 2005 01:34:25 GMT |
|
|
 | In article <1106188445.419685.165470@c13g2000cwb.googlegroups.com>, spinoza1111 @yahoo.com says... > Sorry, I was talking to Programmer Dude. He and I had a battle *royale* > last year, which I won,
Talk about rose-colored glasses. :-)
> My book,
Actually, I removed BOTH plugs (2 in 1 post is so arrogant to get special attention), particularly since its not a good book at all, and the author is suspect at best.
Example: Download the sample code and executables for his "novel" on computer programming, which is (or at least was) available on the Apress website. I hope you have more luck than I did. The executables all crashed with runtime errors on two different computers when I tried them out.
-- Randy Howard (2reply remove FOOBAR)
|
|
 | | From: | Programmer Dude | | Subject: | Re: Javascript help | | Date: | Tue, 18 Jan 2005 11:38:34 -0600 |
|
|
 | smilelots4@yahoo.com writes:
> I am trying to validate the format of telephone number (xxx-xxxx) > This is what i have so far (which also has other validations such as > check to see if there are any inputs in the text box-but that script > works) > > function fncTest() > { > x=document.UpdateInput > set=/^\d{3}-\d{4}$/ > > if (!x.txtPhone.match(set)){ > alert( "Please phone number" ); > return false; > } > } > > is there something wrong with my syntax?
Well, usually "i" is capitalized, and there should usually be a comma before words like "such" and "but", but.......
Oh, did you mean the JavaScript? :-)
Try this:
function Validate_Phone () { var frm = document.myForm; var re = /^\d{3}-\d{4}$/;
if (!frm.txtPhone.value.match(re)) { alert("Not a valid phone number!"); frm.txtPhone.focus(); return false; } return true; }
The main thing you were missing is taking the .value of the input control. You need to get the string object from it. The control itself has no .match() method.
As an improvement, work with the control object directly:
function Validate_Phone () { var ctrl = document.myForm.txtPhone; var re = /^\d{3}-\d{4}$/;
if (!ctrl.value.match(re)) { alert("Not a valid phone number!"); ctrl.focus(); return false; } return true; }
|
|
 | | From: | spinoza1111 at yahoo.com | | Subject: | Re: Javascript help | | Date: | 23 Jan 2005 17:20:18 -0800 |
|
|
 | Randy Howard wrote: > In article <1106188445.419685.165470@c13g2000cwb.googlegroups.com>, spinoza1111 > @yahoo.com says... > > Sorry, I was talking to Programmer Dude. He and I had a battle *royale* > > last year, which I won, > > Talk about rose-colored glasses. :-) > > > My book, > > Actually, I removed BOTH plugs (2 in 1 post is so arrogant to get special > attention), particularly since its not a good book at all, and the > author is suspect at best. > > Example: Download the sample code and executables for his "novel" on > computer programming, which is (or at least was) available on the Apress > website. I hope you have more luck than I did. The executables all > crashed with runtime errors on two different computers when I tried them > out.
This is libel, Mr. Howard. The executables ran fine for most users world-wide. Prior to being made available they were technically evaluated at Apress thoroughly and ran by, among others, Dan Appleman (the leading VB.Net expert). He was able to run the executables without any problems.
I also double checked all the executables on the publication date on a new machine, and, of course, they worked.
Of course, the current Administration has set a very good example in transforming its incompetence into someone else's problem and finds many emulators among damaged souls.
More than one independent reviewer has noticed that Build Your Own .Net Language and Compiler provides MUCH MORE code, of much higher quality, than the usual computer book. At 26000 lines it may have overwhelmed your Radio Shack PC. I suggest you upgrade.
In the past, attorneys have advised me to in general ignore libel on public newsgroups which unlike general book publication and moderated newsgroups are available as kiosks for the damaged. However, based on this post, I need to get a second opinion from an attorney in San Francisco during my visit to the Moronic Inferno (the USA) next month.
The book is still available, of course. Sales are not what I'd like them to be because I work for a living and haven't devoted enough time to promotion. I encourage other readers to make their own judgements on this unique book, which demystifies a technology that can be used, as I show, to solve real problems, > > -- > Randy Howard (2reply remove FOOBAR)
|
|
|