Mailing List Archive



Back to the month index Back to the list index

Warren Killian (killianw@wishard.edu)
Wed, 14 Apr 1999 09:35:27 -0400


Message-ID: <3714999F.7F4EE9A@wishard.edu>
Date: Wed, 14 Apr 1999 09:35:27 -0400
From: Warren Killian <killianw@wishard.edu>
Subject: Re: Validation with HTML

CSM30005 wrote:
>
> Hi all,
> I have a database running that is displaying information to a
> web page and also letting people enter information back to the
> database.
>
> I was wondering was there any way throught MSQL or HTML that I
> could stop them from entering text where there should be number
> and vise versa.
>
> Thank
> Brian

Hi Brian,

If you users are entering information into an HTML form, perhaps a
JavaScript could validate that the value entered is a numeric value.

There is an undocumented function in Lite/w3-msql called "typeof()" that
returns that data type for a given value. You might be able to use it
to check the type of value that was entered. At least you could cast
the entered value to an integer and then confirm that it is an integer
before inserting it into your database. It works something like:

        $variable /*The value passed to your script. */
        $variable = (int)$variable /*Cast the variable to an integer*/
        $type = typeof($variable);
        echo("Variable is type: $type.");

Hope this helps.
            

-- 
Thank you,
Warren Killian
Web Specialist, MIS Dept.
Wishard Health Services
1001 W. 10th St.
Indianapolis, IN 46202
killianw@wishard.edu
Ph: 317.630.8954
From tyuhas@neurobio.arizona.edu  Wed Apr 14 11:01:47 1999
Received: from manduca.neurobio.arizona.edu (tyuhas@manduca.neurobio.Arizona.EDU [128.196.108.2])
	by services.bunyip.com (8.8.5/8.8.5) with ESMTP id LAA02722
	for <msql-list@services.bunyip.com>; Wed, 14 Apr 1999 11:01:42 -0400 (EDT)
Received: from localhost (Received: from localhost (tyuhas@localhost)
	by manduca.neurobio.arizona.edu (8.9.2/8.9.0.Beta5) with SMTP id IAA18048
	for <msql-list@services.bunyip.com>; Wed, 14 Apr 1999 08:01:23 -0600 (MDT)
Date: Wed, 14 Apr 1999 08:01:23 -0600 (MDT)
From: Terrill Yuhas <tyuhas@neurobio.arizona.edu>
To: msql-list@services.bunyip.com
Subject: Re: Validation with HTML
In-Reply-To: <199904141321.OAA24766@tyndall.itcarlow.ie>
Message-ID: <Pine.SUN.3.96.990414075607.17985B-100000@manduca.neurobio.arizona.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hi Brian,

Here's a portion of Javascript we have on a form that checks to make sure a certain field contains only alphanumeric characters:

var digits = "0123456789"; var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz" var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

function isLetter (c) { return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) ) }

function isDigit (c) { return ((c >= "0") && (c <= "9")) }

function isAlphanumeric (s)

{ var i; for (i = 0; i < s.length; i++) { // Check that current character is number or letter. var c = s.charAt(i);

if (! (isLetter(c) || isDigit(c) ) ) return false; }

// All characters are numbers or letters. return true; }

and this is the function call:

function validateForm(form) { <snippage> else if (!isAlphanumeric(form.usr_name.value)) { alert("Please use only alpha_numerical characters for your login name."); return false; } }

Hope that helps,

Terrill

On Wed, 14 Apr 1999, CSM30005 wrote:

> Hi all, > I have a database running that is displaying information to a > web page and also letting people enter information back to the > database. > > I was wondering was there any way throught MSQL or HTML that I > could stop them from entering text where there should be number > and vise versa. > > Thank > Brian >