Skip to content

Instantly share code, notes, and snippets.

@matsuda
Created August 16, 2010 08:23
Show Gist options
  • Save matsuda/526623 to your computer and use it in GitHub Desktop.
Save matsuda/526623 to your computer and use it in GitHub Desktop.
「英大文字」「英小文字」「数字」「記号」のうち、単一の1種類のみで構成されることなく、2種類以上が使われていること
# 「英大文字」「英小文字」「数字」「記号」のうち、単一の1種類のみで構成されることなく、2種類以上が使われていること
# http://e-words.jp/p/r-ascii.html
class User
PASSWORD_FORMAT = %r{^
(?![0-9])[\x20-\x7e]*?[0-9][\x20-\x7e]*?|
(?![a-z])[\x20-\x7e]*?[a-z][\x20-\x7e]*?|
(?![A-Z])[\x20-\x7e]*?[A-Z][\x20-\x7e]*?|
(?![!-\/:-@\[-`\{-~])[\x20-\x7e]*?[!-\/:-@\[-`\{-~][\x20-\x7e]*?
$}x
validates_format_of :password, :with => PASSWORD_FORMAT, :message => 'は英大文字・英小文字・数字・記号のうち2種類以上を使ってください。', :allow_nil => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment