1 function soundex(str) { 2 // original from http://phpjs.org/functions/soundex:520 3 4 var i, j, l, r, p = isNaN(p) ? 4 : p > 10 ? 10 : p < 4 ? 4 : p; 5 var m = {BFPV: 1, CGJKQSXZ: 2, DT: 3, L: 4, MN: 5, R: 6}; 6 var r = (s = (str+'').toUpperCase().replace(/[^A-Z]/g, "").split("")).splice(0, 1); 7 var sl = 0; 8 9 sl = s.length; 10 for (i = -1, l = sl; ++i < l;) { 11 for (j in m) { 12 if (j.indexOf(s[i]) + 1 && r[r.length-1] != m[j] && r.push(m[j])) { 13 break; 14 } 15 } 16 } 17 18 return r.length > p && (r.length = p), r.join("") + (new Array(p - r.length + 1)).join("0"); 19 } 20 21 crmForm.all.new_soundex_lastname.DataValue=soundex(crmForm.all.lastname.DataValue);