JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2009, 08:13 PM
gibatul gibatul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 1 gibatul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 11 sec
Reputation Power: 0
Remove special characters and empty spaces

Hi i have a special java code for input strings like:

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 November 6th, 2009, 09:19 PM
gimp's Avatar
gimp gimp is online now
<?PHP user_title("gimp"); ?>
Click here for more information.
 
Join Date: Jan 2005
Location: Internet
Posts: 6,916 gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)gimp User rank is General 41st Grade (Above 100000 Reputation Level)  Folding Points: 1555 Folding Title: Novice Folder
Time spent in forums: 3 Months 15 h 7 m 27 sec
Reputation Power: 3719
Send a message via AIM to gimp
Big sticky. JAVA ISN'T JAVASCRIPT. Read. Thanks.
__________________
Chat Server Project & Tutorial | WiFi-remote-control sailboat (planned) | Joke Thread
“Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.”

Reply With Quote
  #3  
Old November 7th, 2009, 12:24 PM
s-p-n's Avatar
s-p-n s-p-n is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 161 s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level)s-p-n User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 13 h 14 m 11 sec
Reputation Power: 154
Quote:
Originally Posted by gibatul
Hi i have a special java code for input strings like:

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


You don't want to strip out every character that way. You want to only allow certain characters.

Apparently you only want CAPITAL LETTERS in your input field, and nothing more.
Code:
var re = /^([A-Z]+)$/;
str.replace(re,"");


Edit: Or with spaces allowed,
Code:
var re = /^([A-Z\s]+)$/;
str.replace(re,"");
__________________
- The Wise Guy

Last edited by s-p-n : November 7th, 2009 at 12:34 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Remove special characters and empty spaces [Moved from Java Forum]


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek