Something like the below should do the trick:
function fuzzy(pwd) {
if(!pwd || pwd.constructor == String || pwd.length < 3)
return(pwd);
var arr = pwd.split("");
return(arr[0] + new Array(arr.length - 1).join('*') + arr[arr.length - 1]);
}
/* OR */
function fuzzy(pwd) {
if(!pwd || pwd.constructor == String || pwd.length < 3)
return(pwd);
return(pwd.replace(/(.)(.*)(.)/, function(a, b, c, d) {
return(b+ c.replace(/./g, "*") + d); }));
}
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
The first method I posted is pretty simple, it just uses some basic array and string operations. Read the javascript String and Array object documentation and get back if you have any more queries.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734