Sha256: 937b70e5dce2c8c3c51bd1067f860fd4c11deb7e880eb8da06cd501b2da39f59
Contents?: true
Size: 1.51 KB
Versions: 3
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: constructor</b> 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
3 entries across 3 versions & 1 rubygems