configuring username format in authlogic
How can I configure username to only have alphabets (a-z, A-Z), numericals (0-9) and underscores (_) and no other charac开发者_运维问答ters...
validates_format_of :username, :with => /^[A-Za-z\d_]+$/
You can change that to be whatever you want, but just using normal rails validations seems appropriate. Above allows digits, A-Z, a-z, and underscores
I think I found the answer...
acts_as_authentic do |c|
c.validates_format_of_login_field_options = {:with => /^[a-zA-Z0-9_]+$/, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers and underscores no other characters.")}
end
精彩评论