www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-07-2009, 05:44 AM
    gibatul gibatul is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 2
    Remove special characters and empty spaces from input text

    Hi i have a special java code for input strings like (For only first character upper and the rest in lower case):

    Code:
    <script type="text/javascript">
    String.prototype.toCapitalCase = function() {
    var re = /\s/;
    var words = this.split(re);
    re = /(\S)(\S+)/;
    for (i = words.length - 1; i >= 0; i--) {
    re.exec(words[i]);
    words[i] = RegExp.$1.toUpperCase()
    + RegExp.$2.toLowerCase();
    }
    return words.join(' ');
    } 
    </script>
    And in HTML i have it like
    Code:
    <form name="formname">
    <input type="text" name="name" onblur="javascript:this.value=this.value.toCapitalCase();">
    </form>
    I have a question how can i add there a check for special characters and spaces and immediatelly remove them? I had something like this:

    Code:
    function clearText() {
         document.formname.name.value=filterNum(document.formname.name.value)
    
         function filterNum(str) {
              re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
              return str.replace(re, "");
         }
    }
    But i dont know how to make it work in <input> and this is also without spaces check ... Thx for help
    Reply With Quote
      #2  
    Old 11-07-2009, 02:37 PM
    gibatul gibatul is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 2
    Anybody can help me please? this is quite urgent :-)
    Reply With Quote
      #3  
    Old 11-07-2009, 03:09 PM
    Declan1991 Declan1991 is offline
    Moderator
     
    Join Date: Aug 2007
    Posts: 2,699
    return words.join(' ').replace(/[^a-z]/gi,"");
    More information on regular expressions.
    Everything that is put in [^] matches anything that is not what is in the brackets.
    __________________
    If I have helped
    Quote:
    Great wit and madness are near allied, and fine a line their bounds divide.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 07:34 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.