Skip to content

Instantly share code, notes, and snippets.

@dirceu

dirceu/cpf.js Secret

Last active July 19, 2018 01:11
Show Gist options
  • Save dirceu/cc46f465f6957491827f to your computer and use it in GitHub Desktop.
Save dirceu/cc46f465f6957491827f to your computer and use it in GitHub Desktop.
> cpf
'057.253.749-20'
> cpf.replace(/[^\d]/g, '')
'05725374920'
>>> cpf
'05725374920'
>>> "{}.{}.{}-{}".format(cpf[0:3], cpf[3:6], cpf[6:9], cpf[9:11])
'057.253.749-20'
>> cpf
=> "05725374920"
>> "#{cpf[0,3]}.#{cpf[3,3]}.#{cpf[6,3]}-#{cpf[9,2]}"
=> "057.253.749-20"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment