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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Letters-only text-field

    Hi,

    The following function allows "only" numbers to be typed into a textfield. Can this be altered so that "only" letters would be allowed?? I want to use this to gather the first 3 letters of the last name, and I want the visitor to enter letters only, instead of trying to hack my application.

    Function goes...

    function disallowLetters(eventObj, obj)
    {
    var keyCode

    // Check For Browser Type
    if (document.all){
    keyCode=eventObj.keyCode
    }
    else{
    keyCode=eventObj.which
    }

    var str=obj.value

    if(keyCode==46){
    if (str.indexOf(".")>0){
    return false
    }
    }

    if((keyCode<48 || keyCode >58) && (keyCode != 46)){ // Allow only integers and decimal points
    return false
    }

    return true
    }

    ... and then you call it as:
    <input... onKeyPress="return disallowLetters(event, this)">


    Thanks for all the help! You guys are great!

    I.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function isAlpha(evt) {
    var e=new Object();
    e.which=(evt.which)?evt.which:event.keyCode;
    return (e.which>=97 && e.which<=122);
    }
    Hope that helps!

    Happy coding!


  •  

    Posting Permissions

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