If a user clicks on a tag, right now it recognizes the full text (numbers and characters).
returns Popular Tag %82
I've tried:
$tag.click(function(){
var $this = $(this);
var text = $this.text();
var num = text.parseInt();
num.remove();
alert(text)
});
Doesn't do the trick for numbers. So how would I get just the letters? Ie: ignoring BOTH numbers and special characters(%)
Fiddle here! Thanks for you help!
Using 'str. replace() , we can replace a specific character. If we want to remove that specific character, replace that character with an empty string. The str. replace() method will replace all occurrences of the specific character mentioned.
To remove all characters except numbers in javascript, call the replace() method, passing it a regular expression that matches all non-number characters and replace them with an empty string. The replace method returns a new string with some or all of the matches replaced.
The simplest way is to use a regex:
var s = "ABCblahFoo$%^3l";
var letters = s.replace(/[^A-Za-z]+/g, '');
[]
represents a character (or a number of different possible characters)^
means all characters EXCEPT the ones defined in the bracketsA-Z
equals capital lettersa-z
equals lowercase lettersSo... Replace every character that is NOT a letter with the empty string.
jsFiddle Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With