I have a regular expression that currently matches any non-numeric characters:
var.replace(/[^0-9a-zA-Z ]/,'');
I now need to keep the spaces as well as numbers, but I am having difficulty modifying this.
Any help?
I have a regular expression that currently matches any non-numeric characters:
var.replace(/[^0-9a-zA-Z ]/,'');
I now need to keep the spaces as well as numbers, but I am having difficulty modifying this.
Any help?
Share Improve this question asked Feb 13, 2013 at 16:02 JonJon 3,21411 gold badges41 silver badges60 bronze badges 8- 1 What you have doesn't keep spaces and numbers? – Explosion Pills Commented Feb 13, 2013 at 16:04
- Your regex does not match "any non-numeric characters"; it doesn't match alphabetic characters. – Pointy Commented Feb 13, 2013 at 16:04
- your regex matches none alpha-numeric characters .. not only numeric characters – Hussein Nazzal Commented Feb 13, 2013 at 16:06
- @Rohit Jain - I have been trying things, that is why the regex is almost plete, but I apologise for not being the JavaScript guru you expect me to be. – Jon Commented Feb 13, 2013 at 16:07
- [^0-9\s] this will do it .. this will match every thing that is not a number or space – Hussein Nazzal Commented Feb 13, 2013 at 16:08
1 Answer
Reset to default 6here is a regular expression that will match every thing that is not a number or a space ..
[^0-9\s]
explanation hey regex engine :
1- match every thing .
2- ^
--> that's not
3- 0-9
--> a number
4- \s
--> and a space