1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript Input Validation

Discussion in 'JavaScript' started by THT, Feb 14, 2007.

  1. #1
    I need to validate a Text box using javascript

    Id like to do it on keypress so that if a user enters a character they shouldnt, it displays a message.

    The only characters that should be allowed are A-Z 0-9 and all punctuation
    Im trying to do this to avoid people entering foreign characters such as Ĉ è æ

    Should I do this using a regular expression?
    Whats the easiest way to do this?
     
    THT, Feb 14, 2007 IP
  2. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #2
    designcode, Feb 14, 2007 IP
  3. THT

    THT Peon

    Messages:
    686
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, i knwo how regular expressions work

    I just need to know if there is an easier way rather than specifying

    [a-z][0-9] and then all the other special characters i want to allow.......


    Can i just exclude foreign characters?
     
    THT, Feb 14, 2007 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    You can try with this: [\x20-\x7F] or the range you want from ascii table.
     
    ajsa52, Feb 14, 2007 IP