Last active
August 29, 2015 14:05
-
-
Save chsh/114f0996761ce890b784 to your computer and use it in GitHub Desktop.
Simple phone number validator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def phone_valid?(value) | |
| # value should have only digits and hyphens. | |
| return false unless value =~ /^0\d[\d\-]+\d$/ | |
| # value should have 10 or 11 size digits. | |
| return false unless [10,11].include?(value.gsub(/\-/, '').length) | |
| true | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment