drexed-validators 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/validators/currency_validator.rb +2 -4
- data/app/validators/email_validator.rb +2 -4
- data/app/validators/hex_validator.rb +2 -4
- data/app/validators/html_validator.rb +2 -4
- data/app/validators/ip_validator.rb +2 -4
- data/app/validators/name_validator.rb +2 -4
- data/app/validators/password_validator.rb +2 -4
- data/app/validators/phone_validator.rb +4 -6
- data/app/validators/slug_validator.rb +2 -4
- data/app/validators/ssn_validator.rb +2 -4
- data/app/validators/url_validator.rb +2 -4
- data/app/validators/username_validator.rb +2 -4
- data/app/validators/zipcode_validator.rb +2 -4
- data/lib/drexed/validators/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb401faff617c79f4552eef2e631ba6d30b69424
|
4
|
+
data.tar.gz: b5a05bf290f7ce19c1ef831ebf8b45563c237ce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1fe839071d1bae8808f21aa08eb1480feeb04ee1c30d2464d506266efdd4d99a7c66e8d13d57021f40c7417ba435b197aef508683476e726417bb9cd4107a3a
|
7
|
+
data.tar.gz: 21ccaa00fa3527c2f80e8f4736998c835f2cbac14a65a7d0655f6781a60b91b40c5f11b27acd5c810562ac1d65eb4050f051950f8550c0f84c5f06aea04508d1
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class CurrencyValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^\d*+(\.\d{1,2})?$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class EmailValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /\A[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/i
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class HexValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class HtmlValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class IpValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class NameValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /\A([a-zA-Z'-]+\s+){0,4}[a-zA-Z'-]*\z/i
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class PasswordValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^[a-z0-9_-]{6,18}$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
class PhoneFormatValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
8
|
-
end
|
3
|
+
formatted_value = value.gsub(/[\s\.\+\(\)-]*/, "")
|
4
|
+
is_number = !(formatted_value =~ /^[-+]?[0-9]+$/).nil?
|
5
|
+
unless is_number && validate_by_region(options[:region], formatted_value)
|
6
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class SlugValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^[a-z0-9-]+$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class UrlValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^\A([\d]{3}\-[\d]{2}\-[\d]{4}|[\d]{9})\Z$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class UrlValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class UsernameValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^[a-z0-9_-]{3,16}$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class ZipcodeValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
unless
|
4
|
-
|
5
|
-
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
6
|
-
end
|
3
|
+
unless value =~ /^\A[\d]{5}(?:[-|\s][\d]{4})?\Z$/
|
4
|
+
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drexed-validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|