algorithms

1. Junior Member
Join Date
Dec 1969
Posts
13

## algorithms

Hey there!<BR><BR>I&#039m creating a form which needs to do several things. Please help if you can. And keep in mind that I am just a beginner.<BR><BR>1. When entering a birthdate, it has to be valid ...of course. How do i check it so that it is not invalid/future date.<BR>2. When entering a name, how do I validate it so that it is all alphabetical characters and not numbers or white spaces?<BR>3. When entering an age, how do I check it so that it is a whole number within the range of 0 - 125 and contains no decimals?<BR><BR>I was told using algorithms to build a function would be the best way to go about it, however, I do not know much on algorithms and can&#039t find info on it. ...or whichever is the best way to go about it.<BR><BR>Any assistance or advice you have would be much appreciated.<BR><BR>Thank you!<BR>Gail

2. SPG Guest

## RE: algorithms

Okay, we&#039re going to be doing this on the server-side from a form which had a method=post on it. These aren&#039t so much "algorithms" (imo, I didn&#039t put enough thought into these for them to qualify as such) as just little checks to ensure that everything is within expected parameters.<BR><BR>Step 1) You&#039ll need an "On Error Resume Next" because if things aren&#039t valid, they&#039ll probably be tossing out all over the place... If it tosses an error, then the input was invalid and we&#039ll know that for future reference.<BR><BR>Step 2) if cDate(request.form("inputDate")) &#062;= date() then bDate= False else bDate = True<BR>if err &#060;&#062; 0 then bDate = False<BR><BR>The error catches if the machine couldn&#039t convert it to a date, the if catches if the date comes after yesterday.<BR><BR>if cDate(request.form("inputDate")) = dateAdd("d", -1, date()) then the user was born yesterday... [er, sorry &#039bout that...]<BR><BR>2) This should probably be a regular expression. This requires your VBScript engine to be at version (I think) 5.5.<BR><BR>set nameCheck = new RegExp<BR>nameCheck.global = true<BR>nameCheck.pattern = "[^A-Za-z]" &#039This checks for any non (^) letter (A-Za-z)<BR>if nameCheck.test(request.form("name")) or len(cStr(request.form("name"))) = 0 then bName = false else bName = true<BR><BR>That should work -- though if you get a full name ("Scrawny Pale Guy"), it&#039ll return that the name isn&#039t valid because of the spaces...<BR><BR>3) If you have their birthdate, then you don&#039t need to worry about their age! It&#039s:<BR> if dateSerial(year(date()), month(birthdate), day(birthdate)) &#060;= date() then age = year(date()) - year(birthdate) else age = (year(date()) - 1) - year(birthdate)<BR><BR>However, doing a regular expression (as seen above) with a pattern of "[0-9]*" (0-9 for every character) will give you a false if the age is invalid. Note that a 4-year-old insisting that they&#039re 4 and a half will return invalid...<BR><BR>Read and learn.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•