Web Analytics Made Easy -
StatCounter Help to include numbers and alphabets instead of numbers only. - CodingForum

Announcement

Collapse
No announcement yet.

Help to include numbers and alphabets instead of numbers only.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help to include numbers and alphabets instead of numbers only.

    Hi,
    I need to modify the script showed at:
    http://www.the-art-of-web.com/javascript/validate/3/

    Right now it allows entering "numbers only", I need it so that it allows numbers and alphabets only, no special characters or spaces.

    And yes, one more question, does the first part of the code need to be added in the <head> of the document or <body> ?

    Can someone please help?

    Thank you!

    - Xeirus.

    The code at the above URL is as follows:
    Code:
    <script type="text/javascript">
    
      // initialise variable to save cc input string
      var cc_number_saved = "";
    
    </script>
    Code:
    <input type="text" size="24" maxlength="20" name="cc_number" onBlur="
      // save input string and strip out non-numbers
      cc_number_saved = this.value;
      this.value = this.value.replace(/[^\d]/g, '');
    " onFocus="
      // restore saved string
      if(this.value != cc_number_saved) this.value = cc_number_saved;
    ">

  • #2
    change the following line:
    this.value = this.value.replace(/[^\d]/g, '');

    to:
    this.value = this.value.replace(/[^0-9a-z]/ig, '');

    as for where to place the script, you can place it in the head or body. there isn't too much difference expect the order in which they load. on head, script are loaded before any content is shown in browser.

    Comment


    • #3
      Thank you very much, zerokilled!

      - Xeirus.

      Comment

      Working...
      X