How can I remove matching string with comma before or after
Ex :
<input value="1,2,3,4,5,6,7,8,9,10">
jQuery :
var input = $("input");
var val = input.val();
var random = Math.ceil(Math.random() * 10);
var new_val = val.replace(random,"");
input.val(new_val);
Values not look like 1-10 (this is a example)
Problem with how can I remove comman before or after too ?
Think about if matching string has first position and last position. So it's problem
PS : I have to find by string, not index or something else
Playground : http://jsbin.com/ulikof/1/edit
Any ?