Created
March 6, 2011 09:42
-
-
Save prudhvi/857173 to your computer and use it in GitHub Desktop.
Regular Expression to match some common pattern/formats
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
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