The simplest way (if you want to make sure the contents of the text box
match the regular expression is to handle the onchange event of the textbox.
A regular expression cannot check that each individual character is fine.
Well, you could by defining a regex for each character but that would become
unworkable. You may as well not use a regex and just check each character in
turn by handling the keypress events. A regex works on a whole string at
once.
So, to do it, you would define a function, say validate, as follows:
function validate(form) {}
that would check the value of textbox in the form and if it isn't valid,
output some message and set focus back to the textbox.
Then in the select html element for the textbox, you would just have an
onchange="validate(form)" attribute that would validate the textbox's
content when you clicked off the textbox. This could be annoying, though, if
all you want to do is fill in another part of the form. It wouldn't let you
do this - you'd have to get this textbox right before it let you do anything
else.
-----Original Message-----
From: Richard York [mailto:ryork@q...]
Sent: 04 December 2002 17:31
To: JavaScript HowTo
Subject: [javascript_howto] Regular expression match on a select field
in real time
Hello,
I was wondering if anyone had any ideas as to how to do a regular
expression match on a select field in real time.
Here is my project...
I would like a user to be able to type in a few letters in an HTML text
input field and have the select field scroll automatically to matching
values as the user is inputing data, marking that data as selected. I
would like this to happen in real time, without the use of a submit button.
Many thanks in advance for any thoughts on this!
: )
Rich
--------------------------------------------------------------
Peer Information India Pvt Ltd, Mumbai, India