Sha256: 6586a6032d37416b9b66f94845f5f17c7cbd1043992eeadb2f08bf7134e40bd2
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
class PhoneNumberValidator::Validator ## # == Validates US Phone Numbers # # Regular Expression tested using {regexr.com}[https://regexr.com/] # # <b>Raw Regular Expression:</b> # /^(?:(?:[2-9]11)|(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:\x20+|#|x\.?|ext\.?|extension)\s*(\d+))?)$/i # # <b>RegEx Flags:</b> # Regexp::IGNORECASE (i) PHONE_NUMBER_REGEX = Regexp.new('^(?:(?:[2-9]11)|(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:\x20+|#|x\.?|ext\.?|extension)\s*(\d+))?)$', Regexp::IGNORECASE) ## # == Initialize Phone Number # # <b>Method type:</b> # constructor def initialize(phone_number = '+1 (949) 355-6244 ext. 198842') @phone_number = phone_number end ## # == Validation Method # # Checks to see if the phone number the user entered is valid # by testing regex the pattern with the phone number # # <b>Return Type:</b> # boolean def validate_phone_number if (@phone_number.match(PHONE_NUMBER_REGEX)) puts "'%s' is a valid phone number." % @phone_number return true else puts "'%s' is not a valid phone number." % @phone_number return false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
phone_number_validator-0.2.8 | lib/phone_number_validator/validator.rb |