Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    numeric entries from non-us keyboards and reg exp match

    I want to write a javascript function to disallow an entry field from accepting non-numeric entries (except of course, backspace, delete, and some other keys). I've seen some examples of using the event.keycode (or event.which) object to do this. My concern keyboards in different locales. I'm sure there are lots of you out there with different locale keyboards. Do the numeric key codes (key pad and regular numeric) have the same value on all keyboards?? What about keys like + -, up/down arrow, page up/page down, home, end, delete, backspace, insert???

    I don't have access to keyboards from other locales so I must ask here. Is there some document which lists what the keycodes are in all locales (if they are not the same???).

    Also, should I be using the keyup, keydown, or keypress event to filter out keys?

    One last thing. Before I struggle to write one, does anyone have a generic javascript function which can be passed a regular expression and can determine on each keypress whether the current value matches, and reject non-matches??
    Wayne Christian

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    -post deleted because i'm a bad reader and gave the wrong answer-
    Last edited by Choopernickel; 06-16-2003 at 09:12 PM.

  • #3
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so is it pretty much a given that no matter what countries/locales keyboard is used, these values should be the same?
    Wayne Christian

  • #4
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanx for the reply. One more thing.
    If I'm going to try to do a regular expression matcher, am I correct that at the time I'm looking at event.keyCode, the text field .value property does not yet have the entered key? Or does that depend on whether the event is on a keydown, keyup, or keypress ???
    Wayne Christian

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you use regualr expressions, you let them enter it and then validate it.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #6
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a great keyCode tool:
    http://www.w3.org/2002/09/tests/keys.html

    It looks as though the pressed key is entered into the input and appended to its value immediately before the keyDown and keyPress events are triggered. be careful, though, because as you'll see on the above page, the keyCode for a keyPress event is different in many cases from the same key on a keyDown or keyUp event. However, I haven't seen any differences displayed between keyDown and keyUp events.

    Good luck with the locale-specific script!

    edited to add: Mozilla apparently doesn't register a keyCode on the keyPress event when a printable character is used. Rather, it does, but it's always the number 0 - you'll have to look at the charCode property of the event to see which key was pressed on keyPress in Mozilla.

    Opera 6 doesn't do a damned thing on that page.
    Last edited by Choopernickel; 06-16-2003 at 09:41 PM.

  • #7
    Owl
    Owl is offline
    New Coder
    Join Date
    Jun 2002
    Posts
    62
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Wayne,

    <input onkeyup="if(/\D/g.test(value))value=value.replace(/\D/g,'')">

    ( •) (• )
    >>V


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •