Gossamer Forum
Home : Products : DBMan : Installation :

Another dumb question! :D

Quote Reply
Another dumb question! :D
Ok folks... I am slowly getting the hang of this. However, one small issue. I have a field for age in my database form. This is the code in the default.cfg:

Code:
Age => [3, 'numer', 3, 3, 1, '', ''],

The problem is that I want it to accept ONLY numerical characters and not alpha characters. Unfortunately, it is not doing that. What am I doing wrong?

Ziggy
Quote Reply
Re: Another dumb question! :D In reply to
I think it'll work if you try

Code:
Age => [3, 'numer', 3, 3, 1, '', '[\d+]'],

The regular expression means "one or more digits." If you wanted to make the field optional, use

Code:
'[\d*]'

Now, I am new to regular expressions, so somebody might come along and tell me I've made an error. But that's what my book says. Smile



------------------
JPD
Quote Reply
Re: Another dumb question! :D In reply to
As usual, JPD... you are right on the money. The [/d+] worked perfectly.

Thanks for all your help in this matter! My database is up and running and looking great!!

Ziggy
Quote Reply
Re: Another dumb question! :D In reply to
Excellent!!! Ain't it great when it all works?! Smile

Now that you're an expert, I expect to see you here answering questions from the newbies! Wink



------------------
JPD
Quote Reply
Re: Another dumb question! :D In reply to
I am more than willing to do so!! =) BUT... one last silly little question:

I would like to have the number of apps submitted listed below the Permissions in the main menu, if the login has modify rights. Something like this:

"There have been XXX apps submitted to date."

I was thinking maybe I could use a line like:

Code:
|;
if ($per_mod) {
print qq|
<p><$font>
There have been <b>$db_total_hits</b> applications submitted as of today.</font>|;
}


do you think that would work?
Quote Reply
Re: Another dumb question! :D In reply to
actually, I tried it and it DOES print the text... but no numbers are listed. Any suggestions?
Quote Reply
Re: Another dumb question! :D In reply to
You want to know how many records are in the database at a given time?

There's something on the forum about it from a while back, but I couldn't find it and the search doesn't seem to be working.

Seems to me that Alex had a solution, which was something like this:

Code:
$count = 0;
open (DB, "<$db_file_name") or &cgierr("error unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
++$count;
}
close DB;

(Gee, I hope this is right! Smile )

When you go to print out the results, you would say

Code:
|;
if ($per_mod) {
print qq|
<p><$font>
There have been <b>$count</b> applications
submitted as of today.</font>|;
}

But that is not necessarily the number that have been submitted. Deleted records wouldn't be counted.



------------------
JPD
Quote Reply
Re: Another dumb question! :D In reply to
 
Quote:
Age => [3, 'numer', 3, 3, 1, '', '[\d+]'],

Actually, you should use '^\d+$' as the regular expression. You don't need the [ and ] as there is only one item in your class, and you should put the anchor tags ^ and $ so that a user can enter in only numbers, otherwise he can enter in numbers and characters.

Cheers,

Alex
Quote Reply
Re: Another dumb question! :D In reply to
Quick Question?:
Where should i put this script addon?

|;if ($per_mod) {print qq|<p><$font>There have been <b>$count</b> applicationssubmitted as of today.</font>|;}

And how can i call it from web page so it only dispays "there have been (number)application submitted. as of today,
[the actual code that have to be inserted to web page outside of database]
------------------------------------
2.
Alex pointed that ('^\d+$')will dispay only numbers but how about if I want only
5-NUMBERS (ZIPCODE):
should i do ('^\d+$5') or ('^\d+5')

Thanks.
P.S. Alex it's a great program,thank you all for help.
Quote Reply
Re: Another dumb question! :D In reply to
The "there have been x number of entries added" sort of thing would have to be within the database, probably on the html_home page. Unless you wrote a separate script and called it with an SSI on your static page. I don't "do" SSIs, so I can't help you with it, I'm afraid.

If you want people to enter exactly 5 numbers, set the maximum field length for the field to 5 and set the regular expression to '^d{5}'. That will allow only five characters, but will also require that the entry starts with 5 digits. Voila! A five-digit zip code.


------------------
JPD







[This message has been edited by JPDeni (edited May 03, 1999).]
Quote Reply
Re: Another dumb question! :D In reply to
JPD.
IT DOES ONLY ACCEPT DIGITS
BUT ALSO WORKS WITH NUMBERS GRATER THAN 5
NOT SPECIFICLY WITH 5
'^\D{5}'
Quote Reply
Re: Another dumb question! :D In reply to
Not if you set the maximum length to 5.

In the .cfg file, this would be set up like

ZipCode => [0, 'numer', 5, 5, 1, '', '^d{5}'],

(Of course, your field number would probably be different and you can choose whether or not the field would be null.)

It also would be a good idea, if you're not using autogenerate, to set your field up like

<input type="text" name="ZipCode" value="$rec{'ZipCode'}" size=5 maxlength="5">

Then, not only will the script not accept anything longer than 5 digits, but a user can only enter 5 digits in the field.

I am assuming that when you said

Quote:
BUT ALSO WORKS WITH NUMBERS GRATER THAN 5

you meant numbers greater than 5 digits (greater than 99999).

You are right that ^d{5} requires that the string starts with at least 5 digits, but setting the maxlength in the .cfg file allows no more than 5 characters. At least 5 and no more than 5 means exactly 5.

I guess I did forget to mention that setting the maxlength was in the .cfg file. Sorry 'bout that.



------------------
JPD





Quote Reply
Re: Another dumb question! :D In reply to
THAT'S IT tHANKS JPD.