Created
October 22, 2014 18:53
-
-
Save danielbonnell/35c391050cff057739b4 to your computer and use it in GitHub Desktop.
Regex Drills Challenge
This file contains 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 valid_email?(input) | |
regex = /(\w*|\w*[.]\w*|\w*[-]\w*)[@](\w*|\w*[.]\w*|\w*[-]\w*)[.]((\w{2,4})|(\w{2}[.]\w{2,3}))/ | |
regex.match(input) != nil ? true : false | |
end | |
def valid_phone_number?(input) | |
regex = /\d{10}|[(]\d{3}[)]\s\d{3}[-]\d{4}|[(]\d{3}[)][-]\d{3}[-]\d{4}|\d{3}[-]\d{3}[-]\d{4}/ | |
regex.match(input) != nil ? true : false | |
end | |
def valid_password?(input) | |
regex = /^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{8,}$/ | |
regex.match(input) != nil ? true : false | |
end | |
def valid_username?(input) | |
regex = /^(?=.*[^0-9].*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{1,}$/ | |
regex.match(input) != nil ? true : false | |
end | |
def valid_credit_card_number?(input) | |
regex = /^([3-6]+)([0-9]{14,16}|[0-9]{12})$/ | |
regex.match(input) != nil ? true : false | |
end | |
def only_numbers?(input) | |
regex =/^(?=.*[\d].*)(?=.*[^\D]+.*)[\d]{1,}$/ | |
regex.match(input) != nil ? true : false | |
end | |
def only_letters?(input) | |
regex = /^(?=.*[^0-9].*)(?=.*[a-zA-Z]+.*)[a-zA-Z]{1,}$/ | |
regex.match(input) != nil ? true : false | |
end | |
def valid_social_security?(input) | |
regex = /^(\d{9,}|\d{3}[-]\d{2}[-]\d{4})$/ | |
regex.match(input) != nil ? true : false | |
end | |
def valid_zip_code?(input) | |
regex = /^\d{5}|\d{5}[-]\d{4}$/ | |
regex.match(input) != nil ? true : false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment