From a7722e57ee6e10b578457e880f04349f7f9a0f66 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 26 Feb 2013 11:33:11 -0800 Subject: Changes to valid format for usernames. --- users/app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'users/app/models/user.rb') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index e41c2dc..b6e2bad 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -19,8 +19,8 @@ class User < CouchRest::Model::Base :if => :serverside? validates :login, - :format => { :with => /\A[A-Za-z\d_\.]+\z/, - :message => "Only letters, digits, . and _ allowed" } + :format => { :with => /\A[a-z][a-z\d_\.-]*[a-z\d]\z/, + :message => "Only lowercase letters, digits, . - and _ allowed. Login must have at least 2 characters, and begin with a letter, and end with a letter or digit" } validate :login_is_unique_alias -- cgit v1.2.3 From 26bce716526bfc6a59ffbc372d34215ce2242bfe Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 28 Feb 2013 10:36:24 -0800 Subject: Have specific error messages for usernames with incorrect formats. Signed-off-by: jessib --- users/app/models/user.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'users/app/models/user.rb') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index b6e2bad..c9b367f 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -18,9 +18,19 @@ class User < CouchRest::Model::Base :uniqueness => true, :if => :serverside? + # Have multiple regular expression validations so we can get specific error messages: validates :login, - :format => { :with => /\A[a-z][a-z\d_\.-]*[a-z\d]\z/, - :message => "Only lowercase letters, digits, . - and _ allowed. Login must have at least 2 characters, and begin with a letter, and end with a letter or digit" } + :format => { :with => /\A.{2,}\z/, + :message => "Login must have at least two characters"} + validates :login, + :format => { :with => /\A[a-z\d_\.-]+\z/, + :message => "Only lowercase letters, digits, . - and _ allowed."} + validates :login, + :format => { :with => /\A[a-z].*\z/, + :message => "Login must begin with a lowercase letter"} + validates :login, + :format => { :with => /\A.*[a-z\d]\z/, + :message => "Login must end with a letter or digit"} validate :login_is_unique_alias -- cgit v1.2.3