Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17773
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Question on form validation |
| Date | 2012-12-19 16:20 +0100 |
| Organization | albasani.net |
| Message-ID | <kaslv2$j9m$1@news.albasani.net> (permalink) |
| References | <be8abd23-af86-48c7-be3f-a751ce6e574f@googlegroups.com> |
On 2012-12-19 15:57, bravesplace@gmail.com wrote:
> if (Form1.FieldName.value == "")
> {
> alert("Please enter a value for the FIELDNAME field.");
> Form1.FieldName.focus();
> return (false);
> }
>
> How can I use a LIKE type of statement so if they use a word we
> cannot allow such as "Stupid", I can advise them the word is not
> permitted?
To search for a substring, you can use haystack.indexOf(needle). Convert
the values of haystack and needle to lowercase to make the test case
insensitive.
For example:
var haystack = "you guys are stupid!";
var needle = "stupid";
if (haystack.indexOf(needle) > -1) {
//...
}
To match more complicated patterns, you can use regular rexpressions.
They are very powerful, but too complicated to explain here in detail.
If you're trying to implement an effective bad word filter, you're going
to have to do a LOT more work than just matching strings. Users can get
very creative in bypassing such filters (think h4x0r-style text,
deliberate misspellings, similar-looking characters from other
alphabets, etc).
Checks like this should also be done on the server, not in the browser.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question on form validation bravesplace@gmail.com - 2012-12-19 06:57 -0800
Re: Question on form validation Stefan Weiss <krewecherl@gmail.com> - 2012-12-19 16:20 +0100
Re: Question on form validation Danny <dann90038@gmail.com> - 2012-12-19 13:38 -0800
Re: Question on form validation Mike Filbin <michael.filbin@gmail.com> - 2012-12-31 16:07 -0700
Re: Question on form validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-01 01:58 +0100
Re: Question on form validation "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-01 11:35 +0100
csiph-web