Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
## Copyright 2009 Rex Luther Corporation.
## Licensed under the MIT License
def valid_phone
return true if phone.blank?
phone_formats = [
/^\(\d\d\d\) \d\d\d-\d\d\d\d/,
valid = false
phone_formats.each do |format|
if phone.match( format )
valid = true
unless valid
errors.add("Phone format isn't recognized")

No need to loop and have separate regexes. You can use the | operator to permit multiple formats


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment