Skip to content

Commit f44b3df

Browse files
committed
feature/Only allow alphanumeric characters for name
1 parent 209deeb commit f44b3df

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

app/models/user.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class User < ApplicationRecord
33

44
DEFAULT_FOLDER_NAME = 'My First Folder'.freeze
55
BIO_MISSING_TEXT = "This user hasn't updated their bio yet."
6+
ALPHANUMERIC = /\A[a-zA-Z0-9]*\z/.freeze
67

78
has_one_attached :avatar
89

@@ -33,7 +34,7 @@ class User < ApplicationRecord
3334
#TODO: Add tests for this
3435
after_create :create_default_folder
3536

36-
validates :name, presence: true, length: { maximum: 50 }
37+
validates :name, presence: true, length: { maximum: 50 }, format: { with: ALPHANUMERIC }
3738
validates :bio, length: { maximum: 160 }
3839
validates :location, length: { maximum: 30 }
3940

0 commit comments

Comments
 (0)