String.prototype.matchChars= function(str){
var s= this, i= 0, L= this.length, tem= '';
while(i< L){
if(this[i]!= str[i]) return tem;
tem+= this[i];
i+= 1;
}
return tem;
}
function matchcharsinList(s, A){
if(typeof A== 'string') A= A.split(/, */);
for(var j= 0, n= A.length; j<n; j++){
tem= A[j] || '';
A[j]= s.matchChars(tem);
}
return A;
}
alert (matchcharsinList ('1234', '1000, 1200, 1330, 1235'));
/*
A more useful method might allow case insensitive matches,, and a minimum length of a match:
*/
String.prototype.matchChars= function(str, min, ignorecase){
var s= this, i= 0, L= this.length, tem= '';
if(ignorecase){
s= s.toLowerCase();
str= str.toLowerCase();
}
if(min && str.substring(0, min)!= s.substring(0, min)) return '';
while(i< L){
if(this[i]!= str[i]) return tem;
tem+= this[i];
i+= 1;
}
return tem;
}