Sha256: 80f6f13086de4616e603f4bf3ed220b689a032bc86ed9c592e33e0e33373d218
Contents?: true
Size: 1.32 KB
Versions: 6
Compression:
Stored size: 1.32 KB
Contents
## # This class does all of the matching and checking work for the validation of the phone number. class PhoneNumberValidator::Validator ## # The regex pattern for validating US phone numbers # # Regular Expression tested using {regexr.com}[https://regexr.com/] # # The regular expression used can be found in <em>README.rdoc</em> on the documentation's home page 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) ## # initializes the <b>@phone_number</b> instance variable def initialize(phone_number = '+1 (949) 355-6244 ext. 198842') @phone_number = phone_number end ## # 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
6 entries across 6 versions & 1 rubygems