X-MESINK_Sender: lucene-user-return-1396-sivakumart=aditi.com@jakarta.apache.org
X-MESINK_SenderType: SMTP
X-MESINK_MailForType: SMTP
X-MESINK_Inbound: 1
X-MESINK_MailFor: sivakumart@aditi.com
Received: from nagoya.betaversion.org ([192.18.49.131]) by seablvmsgfe.aditi.tech with Microsoft SMTPSVC(5.0.2195.4453); Wed, 10 Apr 2002 02:37:55 -0700
Received: (qmail 134 invoked by uid 97); 10 Apr 2002 09:39:12 -0000
Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
List-Subscribe: <mailto:lucene-user-subscribe@jakarta.apache.org>
List-Help: <mailto:lucene-user-help@jakarta.apache.org>
List-Post: <mailto:lucene-user@jakarta.apache.org>
List-Id: "Lucene Users List" <lucene-user.jakarta.apache.org>
Reply-To: "Lucene Users List" <lucene-user@jakarta.apache.org>
Delivered-To: mailing list lucene-user@jakarta.apache.org
Received: (qmail 123 invoked from network); 10 Apr 2002 09:39:11 -0000
Message-ID: <002e01c1e073$e12d7c80$0b01a8c0@168.1.8.Domainrelevanz>
Reply-To: "Kelvin Tan" <kelvin@relevanz.com>
From: "Kelvin Tan" <kelvin@relevanz.com>
To: <lucene-user@jakarta.apache.org>
Subject: Javascript query validation
Date: Wed, 10 Apr 2002 17:41:24 +0800
Organization: Relevanz Pte Ltd
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_002B_01C1E0B6.EF2F2AC0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
Return-Path: <lucene-user-return-1396-sivakumart=aditi.com@jakarta.apache.org>
X-OriginalArrivalTime: 10 Apr 2002 09:37:55.0946 (UTC) FILETIME=[64C334A0:01C1E073]

This is a multi-part message in MIME format.

------=_NextPart_000_002B_01C1E0B6.EF2F2AC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Note: this file has only been tested in IE 6.0.

Frustrated with curious TokenMgrErrors and ParseExceptions in your web
forms? (I was) Not so good at regular expressions? (I'm not)

See attached for a (simple) implementation of a regex-based javascript query
validator. Currently, only wildcards (*), plus and minus (+, -), parentheses
(round brackets) and field declarers (:) are validated for. The reason's coz
they're the most commonly used (IMHO) and I'm lazy.

If you do add to it/fix any bugs, I'd appreciate if you could drop me a buzz
so I can update it, or post it to the list for everyone to use.

Note: I've found that in IE at least, hitting the enter button with a text
field in focus irritatingly submits the form without giving me a chance to
validate the query. I've had to disable the "Enter" key for the form fields.
Email me offline if you need help with this.

Regards,
Kelvin Tan

Relevanz Pte Ltd
http://www.relevanz.com

180B Bencoolen St.
The Bencoolen, #04-01
S(189648)

Tel: 6238 6229
Fax: 6337 4417


------=_NextPart_000_002B_01C1E0B6.EF2F2AC0
Content-Type: application/octet-stream;
	name="luceneQueryValidator.js"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="luceneQueryValidator.js"

//
// JavaScript Lucene Query Validator
// Author: Kelvin Tan  (kelvin@relevanz.com)
// Date:   10/04/2002

// validates a lucene query.
// @param Form field that contains the query
function doCheckLuceneQuery(queryField)
{
var query =3D queryField.value;
if(query !=3D null && query.length > 0)
{
  var matches =3D query.match(/^(\*)|([^a-zA-Z0-9_]\*)/);

  // check wildcards are used properly
  if(matches !=3D null && matches.length > 0)
  {
    alert("Invalid search query! The wildcard (*) character must be =
preceded by at least one alphabet or number. Please try again.")
    return false;
  }

  // check parentheses are used properly
  matches =3D query.match(/^([^\n()]*|(\(([a-zA-Z0-9_+-:]|\*)+\)))*$/);
  if(matches =3D=3D null || matches.length =3D=3D 0)
  {
    alert("Invalid search query! Parentheses must contain at least one =
alphabet or number. Please try again.")
    return false;
  }

  // check '+' and '-' are used properly     =20
  matches =3D query.match(/^(([^\n+-]*|[+-]([a-zA-Z0-9_:()]|\*)+))*$/);
  if(matches =3D=3D null || matches.length =3D=3D 0)
  {
    alert("Invalid search query! '+' and '-' modifiers must be followed =
by at least one alphabet or number. Please try again.")
    return false;
  }     =20

  // check ':' is used properly
  matches =3D =
query.match(/^(([^\n:]*|([a-zA-Z0-9_]|\*)+[:]([a-zA-Z0-9_]|\*)+))*$/);
  if(matches =3D=3D null || matches.length =3D=3D 0)
  {
    alert("Invalid search query! Field declarations (:) must be preceded =
by at least one alphabet or number and followed by at least one alphabet =
or number. Please try again.")
    return false;
  }

  return true;
}
}

------=_NextPart_000_002B_01C1E0B6.EF2F2AC0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
Content-Type: text/plain;
	charset="us-ascii"

--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
------=_NextPart_000_002B_01C1E0B6.EF2F2AC0--



