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 3 of 3
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Exclamation check if AT LEAST ONE character in a textbox is a letter

    I am looking for a function to attach onto the onKeyUp event of this textbox that will check if AT LEAST ONE character in a textbox is a letter?

    Code:
    				seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
    									   "title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
    									   "class='selects' size='5' onBlur='concatSeats(this.value,"+passNo+",this.id,"+pass+");' onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
    TIA.

    Picco

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Use a regular expression.

    regex I'd use:
    /^.*[a-zA-Z]+.*$/

    (beginning of line/string followed by 0 or more characters followed by one or more letters followed by 0 or more other characters followed by end of line/string)

    I'm not a regex guru, so there may be a better one.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yeap regexp is the clue. But... I have a quest:
    to attach onto the onKeyUp event
    It is a rather unuseful event for your problem... To check if at least one of the characters is something, I guess that onchange or onblur will be proper. If the user has not ended his text, what is the use to capture the string onkeyup? Wouldn't be better to validadte the text at the end, but not while typing?

    What is your final aim? validadte against letters or special characters?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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