Sunday 8 December 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...