jquery - How do I remove letters and dashes and dollar signs in a string using a regular expression? -
I am trying to find all the letters and dash and dollar signals and remove them from a text box.
function numbers (only) (if ($ ('. Sumit'). Val (). IndexOf ([A-Za-z- $])) {$ ('. Sumit' Replace .val (). ([A-Za-z- $], "");}}
That's what I have and I'm pretty sure this is wrong. I am not very good with regular expressions, but I am trying to learn them. Does anyone want to help me and start with completing this function?
So ... You have got the input.
Then you got the function:
numbers = function () {$ ('. Sumit '). Val (). Replace (/ [A-Za-z $ -] / G, ""); Warning ($ ('Sumit.') Val ().); return false; }
I am alert to determine whether the replacement is working or not. It's not like this.
Mark for all non-digits If you want to remove only letters, dashes, and $, But (for example leaving the decimal), your origin should do this amendment:
$ ('. Sumit'). Val () .replace (/ [A-Za-z $ -] / g, "");
(And I like the updated answer for Mark for the same reason; The way in which you can not predict is catching everything.)
< P> For your updated question, the reason value is not changing, because val () returns a new string. This will not change the actual value. To do this, try: $ (' Sumit '). Each (function () {$ (this) .val ($ (this) .val (). Replace (/ [AZA-Z $ -] / g, ""));}); Warning ($ ('Sumit.') Val ().);
I made it in every () call so that each element will be done individually.
Comments
Post a Comment