mirror of
https://github.com/hkalexling/Mango.git
synced 2026-03-20 00:00:48 -04:00
Break util.cr into multiple files
This commit is contained in:
31
src/util/validation.cr
Normal file
31
src/util/validation.cr
Normal file
@@ -0,0 +1,31 @@
|
||||
def validate_username(username)
|
||||
if username.size < 3
|
||||
raise "Username should contain at least 3 characters"
|
||||
end
|
||||
if (username =~ /^[A-Za-z0-9_]+$/).nil?
|
||||
raise "Username should contain alphanumeric characters " \
|
||||
"and underscores only"
|
||||
end
|
||||
end
|
||||
|
||||
def validate_password(password)
|
||||
if password.size < 6
|
||||
raise "Password should contain at least 6 characters"
|
||||
end
|
||||
if (password =~ /^[[:ascii:]]+$/).nil?
|
||||
raise "password should contain ASCII characters only"
|
||||
end
|
||||
end
|
||||
|
||||
def validate_archive(path : String) : Exception?
|
||||
file = nil
|
||||
begin
|
||||
file = ArchiveFile.new path
|
||||
file.check
|
||||
file.close
|
||||
return
|
||||
rescue e
|
||||
file.close unless file.nil?
|
||||
e
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user