st*****@hotmail.com wrote:
If the following line will force the user to input only a number
between 1 and 5, and will give an error to any keypress outside that
range:
onkeyup="if(event.srcElement.value.search(new RegExp('^[1-5]$')))
{alert('Please type in a number between 1 and
5');event.srcElement.value='';return false}"
This is error-prone, incompatible, illegible, and inefficient. You were
looking for
maxlength="1"
onkeyup="if (!/[1-5]/.test(this.value))
{
window.alert('Please type in a number between 1 and 5');
this.value = '';
return false;
}"
instead. It is still awful. For example, I have just switched from that
focused control to the newsreader with Alt+Tab and got the error message.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann