Javascript String isCPF()
String.prototype.isCPF = function(){ var c = this;//from ww w . ja va2 s .c o m if((c = c.replace(/[^\d]/g,"").split("")).length != 11) return false; if(new RegExp("^" + c[0] + "{11}$").test(c.join(""))) return false; for(var s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--); if(c[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false; for(var s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--); if(c[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false; return true; }