JRS: In article <1106659586.444776.34160@f14g2000cwb.googlegroups. com>,
dated Tue, 25 Jan 2005 05:26:26, seen in news:comp.lang.javascript,
brian.newman@wpafb.af.mil posted :
[color=blue]
><title>Air Force Material Command Squadron Commanders' and Directors'
>Course Registration Page </title>[/color]
A thoughtful and internationally-sensitive author would have indicated
which Air Force is being referred to.
[color=blue]
><style type="text/css">[/color]
Forcing the sizes of fonts and suchlike is not considered good practice.
It is possible that you do not, in your application, need to allow for
those with sub-standard vision; but 14-point for ordinary text is too
large to suit me.
[color=blue]
>p {
>font-family: "Times New Roman", Times, serif;
>font-size: 14px;
>}[/color]
[color=blue]
><script type="text/javascript" language="javascript">[/color]
attribute not required
[color=blue]
>function DisplayErrors() {
>if (document.enroll.coursedate.value=="") alert ("Please enter a
>coursedate");[/color]
If you want your code to be readable in News, do not let your posting
agent break lines. A good craftsman chooses good tools.
[color=blue]
>if ((isValidName(document.enroll.firstname.value))==f alse) alert
>("Please enter your first name");[/color]
... == false is not needed; use !... .
Does it matter that some people put family name first, or does your
organisation not allow that?
[color=blue]
>function ValidateForm()
>{
>alert ("form validation started");[/color]
Code should be indented to show intended structure; you have chosen a
badly-designed posting agent which damages readability. A good
craftsman chooses good tools.
(isValidEmail(document.enroll.Spouse_Email)!==fals e))
That's an interesting operator to choose.
[color=blue]
>function isValidDate (testDate) {
>var invalidDate = true;
>//alert ("isValidDate break 1");
>if (testDate.length!==8)
>{
>alert ("date is not of expected length");
>return false;
>}
>datePart = testDate.slice(0,1);
>if (cint(datePart) < 1) OR (cint(datePart) > 12)
>{
>alert ("month is not in expected range");
>return false;
>}
>datePart = testDate.slice (2,3);
>if (cint(datePart < 1)) OR (cint(datePart) > 12)
>{
>alert ("day is not in expected range");
>return false;
>}
>datePart = testDate.slice (4,7);
>if (cint(datePart) < 1950) OR (cint(datePart) > 2050)
>{
>alert ("year is not in expected range");
>return false;
>}
>return true;
>} // end isValidDate function[/color]
Bloated; and I was going to say that it did not discriminate between
months of 28,29,30,31 days. But that pales into insignificance when one
sees that you only allow 12 days in each month.
I know what cint does in VBScript, but not of its use in javascript.
You appear to be checking an 8-digit field; but your strings call for
FFF dates, mm/dd/yyyy. Did you intend to allow a 101-year range?
Proper date validation need not be lengthy; see sig.
[color=blue]
>function isValidName (testName) {
>var myRegExp = /[A-Z][a-z]{1,29}/;
>//alert (myRegExp.test(testName));
>return myRegExp.test(testName);
>} // end isValidName function[/color]
That accepts "Ug", though it rejects "U Thant"
It accepts "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysili ogogogoch"
and also "llanfairpwllgwyngyllgogerychwyrndrobw1111antysiIi ogogogoch".
You may not have expected that. It also accepts "00000Ol111111".
It accepts ("O'Keefe") which IIRC is the name of a NASA boss; but I
suspect that's accidental.
[color=blue]
>function isValidPhone (testPhone) {
>var myRegExp = /[1-9][0-9]{2}-[0-9]{4}/;
>return myRegExp.test(testPhone);[/color]
Appears to require the form ddd-dddd to be somewhere in the input.
Strings call for xxx-xxx-xxxx.
[color=blue]
>} // end isValidPhone function
>
>function isValidEmail (testEmail) {
>var myRegExp =
>/[a-z0-9.]{1,40}@[a-z0-9.]{4,65}.(com|net|org|info|biz|([a-z]{2,3}.[a-z]{2}))/;
>return myRegExp.test(testEmail)
>} // end isValidEmail function[/color]
Rejects many valid left parts. Rejects "xxx@yyy.co.uk", which is valid.
Accepts "##x@yy7y.co.uk" which may be valid but is evidently not
intended. Accepts "Joe
Stalin@yy7y.Leonid Brezhnev") .
[color=blue]
>function getStyleObject (objectId) {
>//alert ("begin getSyleObject");[/color]
^ <G>[color=blue]
>//if (document.getElementById && document.getElementById(objectId))
>{
>//alert ("break 1 in getStyleObject");
>return document.getElementById(objectId).style;
>//}
>//else if (document.all && document.all(objectId)) {
>//alert ("break 2 in getStyleObject");
>//return document.all(objectId).style;
>//}
>//else if (document.layers && document.layers[objectId]) {
>//alert ("break 3 in getStyleObject");
>//return document.layers[objectId];
>//}
>//else {
>//alert ("break 4 in getStyleObject");
>//return false;
>//}
>//alert ("end getSyleObject");
>}[/color]
Does that mean that your Air Force still has Netscape 4???
[color=blue]
>function suspendSpouse(objectId) {[/color]
Seems a tactless function identifier <g>.
ISTM that your Air Force should employ a programmer to do your task.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.