Page 1 of 1

JavaScript: comparing values with an array members

Posted: Mon Oct 04, 2004 1:22 pm
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!

Posted: Mon Oct 04, 2004 1:36 pm
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..

...

Posted: Tue Oct 05, 2004 3:34 am
by Calimero
And those are ?

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

...

Posted: Tue Oct 05, 2004 3:43 am
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

...

Posted: Tue Oct 05, 2004 8:45 am
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

Posted: Wed Oct 06, 2004 2:59 am
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.