Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiangenco/8348162 to your computer and use it in GitHub Desktop.
Save christiangenco/8348162 to your computer and use it in GitHub Desktop.
Simple Rails bitcoin address validation. Doesn't calculate the checksum or anything fancy - just checks that the address starts with a 1 or 3, consists only of alphanumeric characters, and is 27-34 characters long (from https://en.bitcoin.it/wiki/Address).
class User < ActiveRecord::Base
validates :bitcoin_address, format: { with: /\A(1|3)[a-zA-Z1-9]{26,33}\z/,
message: "invalid bitcoin address" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment