Skip to content

Instantly share code, notes, and snippets.

@danielbonnell
Created October 22, 2014 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbonnell/35c391050cff057739b4 to your computer and use it in GitHub Desktop.
Save danielbonnell/35c391050cff057739b4 to your computer and use it in GitHub Desktop.
Regex Drills Challenge
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