class AlphaNumericValidator
Constants
- PUNCTUATION_REGEXP
- WHITESPACE_EXCEPTIONS
Public Instance Methods
has_whitespace?
click to toggle source
returns true if the string contains whitespace
# File lib/rails/alpha_numeric_validator.rb, line 80 def has_whitespace? @string.to_s.match /(?:\s)+/ end
is_valid?
click to toggle source
alias for :is_valid_string?
# File lib/rails/alpha_numeric_validator.rb, line 58 def is_valid? is_valid_string? end
is_valid_string?
click to toggle source
returns true if the string only contains the requested character set
TODO: support international DNS
# File lib/rails/alpha_numeric_validator.rb, line 69 def is_valid_string? return false if !@options[:allow_whitespace] && has_whitespace? re = PUNCTUATION_REGEXP[@options[:punctuation].to_s.to_sym] @string.to_s.gsub(re, "").blank? end