Created
March 23, 2012 18:38
-
-
Save tboyko/2173624 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
validates :enrollment_method, | |
presence: true, | |
inclusion: { | |
in: ['email', 'phone_number'] | |
} | |
validates :email, | |
presence: true, | |
format: { | |
with: /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/, | |
message: "is not of the correct format"}, | |
if: lambda { |device| | |
device.enrollment_method == 'email' | |
} | |
validates :phone_number, | |
presence: true, | |
format: { | |
with: /^[\D]*1?([\D]*[\d][\D]*){10}[\D]*$/, # 10 digits in string, optionally starts with "1" to make 11. | |
message: "is not a valid US phone number"}, | |
if: lambda { | |
|device| device.enrollment_method == 'phone_number' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment