Skip to content

Instantly share code, notes, and snippets.

@prudhvi
Created March 6, 2011 09:42
Show Gist options
  • Save prudhvi/857173 to your computer and use it in GitHub Desktop.
Save prudhvi/857173 to your computer and use it in GitHub Desktop.
Regular Expression to match some common pattern/formats
emailregex = /\A\w+.\w+@\w+.com\Z/
phoneregex = /\A\d{3}-?\d{3}-?\d{4}\Z/
puts "Enter email id"
email = gets
if emailregex.match(email)
puts "Email pattern matched"
else
puts "Email format is wrong"
end
puts "Enter US phone number"
phone = gets
if phoneregex.match(phone)
puts "Phonenumber pattern matched"
else
puts "Phone number format is wrong"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment