/    Sign up×
Community /Pin to ProfileBookmark

onkeyup tabkey

Hi – fairly new, so hope this isn’t a silly question. I’m using a clientside javascript function to validate user input. The function is triggered by an onkeyup which passes the input data in a table (input type = “text”).

The function includes

validChars = /[1-9]/
if(inputNumber.value.match(validChars)) to determine a response.

This works fine except that the tab key which moves from cell to cell in the input table also triggers an invalid input. I’ve tried including t to allow tab through but this doesn’t work.

Second question (if I may) how do I allow arrow keys in HTML for user movement from cell to cell, as well as tab key?

Your help for a newbie much appreciated!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@007JulienJul 10.2012 — Your regular expression is made to test only one character ! She can thus work only by testing the last character read with a charCode or keyCode... If you test the full entry with a value, you have to test many characters with something like this /^[t1-9]+$/ or this to allows zeros after the first character /^[t1-9][0-9]+$/. A variant could consists to make the test with a onblur event...

For the second question your have all to do by catching an event (keypress, keydown or keyup) an play with the focus. But there is probably solutions on the web...
Copy linkTweet thisAlerts:
@alanbauthorJul 10.2012 — The input field is only one character, which is why i did it that way, But I can see what you mean, its testing the tab key rather than the entry. Not quite sure I follow the solution, though. . .
×

Success!

Help @alanb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...