Thursday, 22 June 2017

javascript - how to match all special characters except a comma



What's the regex values for to match a string against all special characters and letters except a comma.




value = "23,$%aA";


I want to do a match if the value has any pf the special characters and letters like the above string then it will return true but if it just has a value like



value = "23,3456.00"



then it will return false. As all the special characters and letters are no longer part of the string.



Can I do this using match and regex.



Answer



This will match everything that is not numeric or not a comma or period (decimal point)



var result = str.replace(/[^0-9\.,]/g, "");

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...