diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index 7deb36562..99dd910ab 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -16,6 +16,8 @@ module Depp ['Birthday', 'birthday'] ] + validates :phone, e164: true, phone: true + class << self attr_reader :epp_xml, :user @@ -144,6 +146,8 @@ module Depp end def save + return false if !valid? + hash = { id: { value: code }, postalInfo: { @@ -166,13 +170,14 @@ module Depp hash[:id] = nil if code.blank? create_xml = Depp::Contact.epp_xml.create(hash, extension_xml(:create)) - data = Depp::Contact.user.request(create_xml) self.id = data.css('id').text handle_errors(data) end def update_attributes(params) + return false if !valid? + self.ident_country_code = params[:ident_country_code] self.ident_type = params[:ident_type] self.ident = params[:ident] diff --git a/app/views/registrar/contacts/form/_general.haml b/app/views/registrar/contacts/form/_general.haml index 77443903d..5f1c90098 100644 --- a/app/views/registrar/contacts/form/_general.haml +++ b/app/views/registrar/contacts/form/_general.haml @@ -56,7 +56,8 @@ .col-md-3.control-label = f.label :email, t(:email) + '*' .col-md-7 - = f.email_field :email, class: 'form-control', required: true + = f.email_field :email, class: 'form-control', required: true, + pattern: "[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" .form-group .col-md-3.control-label diff --git a/config/locales/en.yml b/config/locales/en.yml index 069f997ce..31947350d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -377,6 +377,11 @@ en: activemodel: errors: models: + 'depp/contact': + attributes: + phone: + invalid: "Phone number must be in +XXX.YYYYYYY format" + too_long: "Phone number is too long" 'depp/user': attributes: base: diff --git a/lib/validators/e164_validator.rb b/lib/validators/e164_validator.rb index e5807e585..72e805fd9 100644 --- a/lib/validators/e164_validator.rb +++ b/lib/validators/e164_validator.rb @@ -5,7 +5,7 @@ class E164Validator < ActiveModel::EachValidator length_validator.validate(record) format_validator = ActiveModel::Validations:: - FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/, + FormatValidator.new(with: /\A\+[0-9]{1,3}\.[0-9]{1,14}\z/, attributes: attribute) format_validator.validate(record) end