Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Check for period immediately after @
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Nov 8, 2016
1 parent 8cd5023 commit 9d34cfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/services/form_validator.rb
@@ -1,10 +1,13 @@
# frozen_string_literal: true
#
class FormValidator
MAX_LENGTH = {
PARAGRAPH: 10_000,
TEXT: 250
}.freeze

EMAIL_REGEXP = /\A(?!.*\.{2})(?!.*@\.)(?!.*\.+@)[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\z/i

def initialize(params, form_elements = nil)
@params = params.symbolize_keys
@errors = Hash.new { |hash, key| hash[key] = [] }
Expand Down Expand Up @@ -98,9 +101,7 @@ def validate_postal(postal, form_element)
end

def is_email?(candidate)
/\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\z/i =~ candidate &&
!(/\.\./ =~ candidate) && # Doesn't have two consecutive dots
!(/\A.*\.@/ =~ candidate) # Doesn't have a dot just before the @
!(EMAIL_REGEXP =~ candidate).nil?
end

def is_phone(candidate)
Expand Down
5 changes: 5 additions & 0 deletions spec/services/form_validator_spec.rb
Expand Up @@ -124,6 +124,11 @@
expect(subject).to_not be_valid
end

it 'with a dot just after the @' do
params[:email] = 'this@.other.com'
expect(subject).to_not be_valid
end

it 'with a two consecutive dots' do
params[:email] = 'thi..s@other..com'
expect(subject).to_not be_valid
Expand Down

0 comments on commit 9d34cfa

Please sign in to comment.