Skip to content

Instantly share code, notes, and snippets.

View ricardoriogo's full-sized avatar

Ricardo Riogo ricardoriogo

View GitHub Profile
@ricardoriogo
ricardoriogo / jquery.validate.cnpj.js
Last active April 20, 2017 13:40
CNPJ validation for jQuery Validate
jQuery.validator.addMethod("cnpj", function(cnpj, element) {
var numeros, digitos, soma, resultado, pos, tamanho,
digitos_iguais = true;
if (cnpj.length < 14 && cnpj.length > 15)
return false;
for (var i = 0; i < cnpj.length - 1; i++)
if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
@ricardoriogo
ricardoriogo / jquery.validate.cpf.js
Last active October 11, 2016 18:26
CPF validation for jQuery Validate
jQuery.validator.addMethod("cpf", function(value, element) {
value = value.replace('.','');
value = value.replace('.','');
cpf = value.replace('-','');
while(cpf.length < 11) cpf = "0" + cpf;
var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
var a = [];
var b = new Number;
var c = 11;
for (i=0; i<11; i++){
@ricardoriogo
ricardoriogo / number_format.js
Created December 6, 2012 18:39
Javascript version of php number_format function
function number_format (number, decimals, dec_point, thousands_sep) {
// http://kevin.vanzonneveld.net
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfix by: Michael White (http://getsprink.com)
// + bugfix by: Benjamin Lupton
// + bugfix by: Allan Jensen (http://www.winternet.no)
// + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + bugfix by: Howard Yeend
// + revised by: Luke Smith (http://lucassmith.name)