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
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Text only fields

    Hello all

    I have been searching for about an hour for a functions that will not allow numbers in a text fields and have no luck.

    There are lots of code out there written for 'numeric only' fields but does anyone have a sample of a fields that only allows TEXT?

    Please post the full code (form, script, etc.)
    tGirl

  • #2
    Regular Coder
    Join Date
    Nov 2005
    Posts
    329
    Thanks
    3
    Thanked 19 Times in 19 Posts
    You'll find it here -

    http://www.jsmadeeasy.com/javascript.../list_test.asp

    Although I gues you'd have to tweak it a bit to adapt to what you require.

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,495
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <input onkeyup="this.value=this.value.replace(/\d/g,'');"  />
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #4
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Vic where is the actual script?
    tGirl

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    the important part is the regular expression:

    /\d/

    If you put this into string.match, it will return the number of numbers in the text, so:

    "abcdefg".match(/\d/) == 0

    "abc2defg".match(/\d/) == 1

    "ab3cde4fg".match(/\d/) == 2

    So you can test input.value.match(/\d/) for being greater than 0 to tell if there are numbers or not.

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,495
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Vic where is the actual script?

    this is the bit that does the filter

    .replace(/\d/g,'');

    means

    if any character is a digit replace it with ''

    \d = any digit

    g = any character in the string
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #7
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Guys I am a newbie which is why I am asking questions on the list.

    posting pieces of code is still like a foreign language to me.

    Can you send me the script and form field syntax?
    tGirl


  •  

    Posting Permissions

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