JavaScript: comparing values with an array members

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

JavaScript: comparing values with an array members

Post by Calimero »

I have input field, and want the each word form it - to check against the array of (predefined - forbiden words).

I already have delimited them,a nd basically created an array of them.

So is there a built in function inside JavaScript to check one against another or if someone has the code.

Thanks Ahead!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a regular expression over the value can do it in one push. however, I'd suggest not doing it in Javascript for all the usual reasons..
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

And those are ?

I'm new to JS, so any tip welcome - or even URL where to dig about usual reasons.

...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

One of the usual caveats would be that if you are only doing this checking on the client-side then it is easily circumvented.

Regular expressions in JavaScript is probably a Google job ;)

Mac
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Well in that case yes,

But my idea was to do the checking on the client side - for all those who use my site accordingly - both sides are better (in speed, processing ...)

And of course if someone tries to abuse that - backup is in PHP - so it is only executed when the JS is not used.

Is this ok, from the expert's point of view.

:D
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Normally when using Javascript you would check both on the client side (correcting where necessary). Then you would also check server side (PHP) as though no Javascript was used. Those with Javascript have the advantage of no page reload for initial checking but no invalid data can be used/hacked on the server. Design for no Javascript then build additional Javascript features, not the other way around.
Post Reply