Embedded Ruby form - validating email with specific domainHow to validate an email address in JavaScript?How to validate an email address using a regular expression?Validating email address with single character domain-names with a regexHow to install a specific version of a ruby gem?How to allow “+” character in email validation?bootstrap navbar search embedded rubyRegex Python validating an emailResearchKit: Validate emailRegex for Email Address validationUse pattern to validate email addresses
Why do some games show lights shine through walls?
What is this opening trap called, and how should I play afterwards? How can I refute the gambit, and play if I accept it?
Rvalues, lvalues and formal definitions
Does squid ink pasta bleed?
Is there any reason to avoid sunglasses with blue lenses?
Alphabet completion rate
Why cruise at 7000' in an A319?
When is it ok to add filler to a story?
Are Finite Automata Turing Complete?
How to determine what is the correct level of detail when modelling?
First-year PhD giving a talk among well-established researchers in the field
Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback
Singing along to guitar chords (harmony)
How to append a matrix element by element?
STM Microcontroller burns every time
Declining an offer to present a poster instead of a paper
Impossible darts scores
Swapping rooks in a 4x4 board
Ending: accusative or not?
How well known and how commonly used was Huffman coding in 1979?
Does the Distant Spell metamagic apply to the Sword Burst cantrip?
Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?
Should I hide continue button until tasks are completed?
Are there any vegetarian astronauts?
Embedded Ruby form - validating email with specific domain
How to validate an email address in JavaScript?How to validate an email address using a regular expression?Validating email address with single character domain-names with a regexHow to install a specific version of a ruby gem?How to allow “+” character in email validation?bootstrap navbar search embedded rubyRegex Python validating an emailResearchKit: Validate emailRegex for Email Address validationUse pattern to validate email addresses
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am creating an embedded Ruby form and I would like the validation to allow 9 characters before the beginning, but specifcially starting with an 'x', so x12345678@a2z.ie would be a valid email while 12345678@a2z.ie would not be valid.
a2z.ie is the domain and is required.
I have the REGEX code: x+d8+@a2z.ie
The code I have is this:
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", :class => 'form-control', :validation => 'x+d8+@a2z.ie' %>
</div>
I know this code is wrong because it still allows any user's email.
regex ruby
add a comment |
I am creating an embedded Ruby form and I would like the validation to allow 9 characters before the beginning, but specifcially starting with an 'x', so x12345678@a2z.ie would be a valid email while 12345678@a2z.ie would not be valid.
a2z.ie is the domain and is required.
I have the REGEX code: x+d8+@a2z.ie
The code I have is this:
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", :class => 'form-control', :validation => 'x+d8+@a2z.ie' %>
</div>
I know this code is wrong because it still allows any user's email.
regex ruby
Try:validation => /Axd8@a2z.iez/
– Wiktor Stribiżew
Mar 25 at 11:00
If:validation
does not work, try replacing it with:pattern
– Wiktor Stribiżew
Mar 25 at 11:06
@WiktorStribiżew:validation => /Axd8@a2z.iez/
did not work.:validation => '/Axd8@a2z.iez/'
did not work.:pattern => /Axd8@a2z.iez/
did not work.:pattern => '/Axd8@a2z.iez/'
did not work. :(
– TattooedJoey
Mar 25 at 12:06
Do not put the regex inside single quotes, it will never work. So, the problem is not just with regex, you need to fix your code.
– Wiktor Stribiżew
Mar 25 at 12:07
1
@WiktorStribiżew I tried both with and without, none worked.
– TattooedJoey
Mar 25 at 12:08
add a comment |
I am creating an embedded Ruby form and I would like the validation to allow 9 characters before the beginning, but specifcially starting with an 'x', so x12345678@a2z.ie would be a valid email while 12345678@a2z.ie would not be valid.
a2z.ie is the domain and is required.
I have the REGEX code: x+d8+@a2z.ie
The code I have is this:
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", :class => 'form-control', :validation => 'x+d8+@a2z.ie' %>
</div>
I know this code is wrong because it still allows any user's email.
regex ruby
I am creating an embedded Ruby form and I would like the validation to allow 9 characters before the beginning, but specifcially starting with an 'x', so x12345678@a2z.ie would be a valid email while 12345678@a2z.ie would not be valid.
a2z.ie is the domain and is required.
I have the REGEX code: x+d8+@a2z.ie
The code I have is this:
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", :class => 'form-control', :validation => 'x+d8+@a2z.ie' %>
</div>
I know this code is wrong because it still allows any user's email.
regex ruby
regex ruby
asked Mar 25 at 10:59
TattooedJoeyTattooedJoey
185 bronze badges
185 bronze badges
Try:validation => /Axd8@a2z.iez/
– Wiktor Stribiżew
Mar 25 at 11:00
If:validation
does not work, try replacing it with:pattern
– Wiktor Stribiżew
Mar 25 at 11:06
@WiktorStribiżew:validation => /Axd8@a2z.iez/
did not work.:validation => '/Axd8@a2z.iez/'
did not work.:pattern => /Axd8@a2z.iez/
did not work.:pattern => '/Axd8@a2z.iez/'
did not work. :(
– TattooedJoey
Mar 25 at 12:06
Do not put the regex inside single quotes, it will never work. So, the problem is not just with regex, you need to fix your code.
– Wiktor Stribiżew
Mar 25 at 12:07
1
@WiktorStribiżew I tried both with and without, none worked.
– TattooedJoey
Mar 25 at 12:08
add a comment |
Try:validation => /Axd8@a2z.iez/
– Wiktor Stribiżew
Mar 25 at 11:00
If:validation
does not work, try replacing it with:pattern
– Wiktor Stribiżew
Mar 25 at 11:06
@WiktorStribiżew:validation => /Axd8@a2z.iez/
did not work.:validation => '/Axd8@a2z.iez/'
did not work.:pattern => /Axd8@a2z.iez/
did not work.:pattern => '/Axd8@a2z.iez/'
did not work. :(
– TattooedJoey
Mar 25 at 12:06
Do not put the regex inside single quotes, it will never work. So, the problem is not just with regex, you need to fix your code.
– Wiktor Stribiżew
Mar 25 at 12:07
1
@WiktorStribiżew I tried both with and without, none worked.
– TattooedJoey
Mar 25 at 12:08
Try
:validation => /Axd8@a2z.iez/
– Wiktor Stribiżew
Mar 25 at 11:00
Try
:validation => /Axd8@a2z.iez/
– Wiktor Stribiżew
Mar 25 at 11:00
If
:validation
does not work, try replacing it with :pattern
– Wiktor Stribiżew
Mar 25 at 11:06
If
:validation
does not work, try replacing it with :pattern
– Wiktor Stribiżew
Mar 25 at 11:06
@WiktorStribiżew
:validation => /Axd8@a2z.iez/
did not work. :validation => '/Axd8@a2z.iez/'
did not work. :pattern => /Axd8@a2z.iez/
did not work. :pattern => '/Axd8@a2z.iez/'
did not work. :(– TattooedJoey
Mar 25 at 12:06
@WiktorStribiżew
:validation => /Axd8@a2z.iez/
did not work. :validation => '/Axd8@a2z.iez/'
did not work. :pattern => /Axd8@a2z.iez/
did not work. :pattern => '/Axd8@a2z.iez/'
did not work. :(– TattooedJoey
Mar 25 at 12:06
Do not put the regex inside single quotes, it will never work. So, the problem is not just with regex, you need to fix your code.
– Wiktor Stribiżew
Mar 25 at 12:07
Do not put the regex inside single quotes, it will never work. So, the problem is not just with regex, you need to fix your code.
– Wiktor Stribiżew
Mar 25 at 12:07
1
1
@WiktorStribiżew I tried both with and without, none worked.
– TattooedJoey
Mar 25 at 12:08
@WiktorStribiżew I tried both with and without, none worked.
– TattooedJoey
Mar 25 at 12:08
add a comment |
1 Answer
1
active
oldest
votes
Used an email validator Ruby file instead.
Using Devise as well, if that helps.
In user.rb, add:
validates :email, :presence => true, :email => true
Create a validators
folder in models. Then create email_validator.rb in said folder and add this to it:
(app/models/validators/email_validator.rb) :
require 'mail'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain, the domain has at least
# one '.' and that value is an email address
r = m.domain.present? && m.domain.match('.') && m.address == value
s = m.domain.present? && m.domain.match('@a2z.ie') && m.address == value
# Update 2015-Mar-24
# the :tree method was private and is no longer available.
# t = m.__send__(:tree)
# We need to dig into treetop
# A valid domain must have dot_atom_text elements size > 1
# user@localhost is excluded
# treetop must respond to domain
# We exclude valid email values like <user@localhost.com>
# Hence we use m.__send__(tree).domain
# r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue
r = false
end
record.errors[attribute] << (options[:message] || "is invalid. Please enter xEMPLOYEENUMBER@a2z.ie, e.g. x12345678@a2z.ie") unless (r && s)
end
end
Wasn't exactly what I wanted, but is somewhat.
Ref: https://github.com/plataformatec/devise/wiki/How-to:-Use-a-custom-email-validator-with-Devise
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336290%2fembedded-ruby-form-validating-email-with-specific-domain%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Used an email validator Ruby file instead.
Using Devise as well, if that helps.
In user.rb, add:
validates :email, :presence => true, :email => true
Create a validators
folder in models. Then create email_validator.rb in said folder and add this to it:
(app/models/validators/email_validator.rb) :
require 'mail'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain, the domain has at least
# one '.' and that value is an email address
r = m.domain.present? && m.domain.match('.') && m.address == value
s = m.domain.present? && m.domain.match('@a2z.ie') && m.address == value
# Update 2015-Mar-24
# the :tree method was private and is no longer available.
# t = m.__send__(:tree)
# We need to dig into treetop
# A valid domain must have dot_atom_text elements size > 1
# user@localhost is excluded
# treetop must respond to domain
# We exclude valid email values like <user@localhost.com>
# Hence we use m.__send__(tree).domain
# r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue
r = false
end
record.errors[attribute] << (options[:message] || "is invalid. Please enter xEMPLOYEENUMBER@a2z.ie, e.g. x12345678@a2z.ie") unless (r && s)
end
end
Wasn't exactly what I wanted, but is somewhat.
Ref: https://github.com/plataformatec/devise/wiki/How-to:-Use-a-custom-email-validator-with-Devise
add a comment |
Used an email validator Ruby file instead.
Using Devise as well, if that helps.
In user.rb, add:
validates :email, :presence => true, :email => true
Create a validators
folder in models. Then create email_validator.rb in said folder and add this to it:
(app/models/validators/email_validator.rb) :
require 'mail'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain, the domain has at least
# one '.' and that value is an email address
r = m.domain.present? && m.domain.match('.') && m.address == value
s = m.domain.present? && m.domain.match('@a2z.ie') && m.address == value
# Update 2015-Mar-24
# the :tree method was private and is no longer available.
# t = m.__send__(:tree)
# We need to dig into treetop
# A valid domain must have dot_atom_text elements size > 1
# user@localhost is excluded
# treetop must respond to domain
# We exclude valid email values like <user@localhost.com>
# Hence we use m.__send__(tree).domain
# r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue
r = false
end
record.errors[attribute] << (options[:message] || "is invalid. Please enter xEMPLOYEENUMBER@a2z.ie, e.g. x12345678@a2z.ie") unless (r && s)
end
end
Wasn't exactly what I wanted, but is somewhat.
Ref: https://github.com/plataformatec/devise/wiki/How-to:-Use-a-custom-email-validator-with-Devise
add a comment |
Used an email validator Ruby file instead.
Using Devise as well, if that helps.
In user.rb, add:
validates :email, :presence => true, :email => true
Create a validators
folder in models. Then create email_validator.rb in said folder and add this to it:
(app/models/validators/email_validator.rb) :
require 'mail'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain, the domain has at least
# one '.' and that value is an email address
r = m.domain.present? && m.domain.match('.') && m.address == value
s = m.domain.present? && m.domain.match('@a2z.ie') && m.address == value
# Update 2015-Mar-24
# the :tree method was private and is no longer available.
# t = m.__send__(:tree)
# We need to dig into treetop
# A valid domain must have dot_atom_text elements size > 1
# user@localhost is excluded
# treetop must respond to domain
# We exclude valid email values like <user@localhost.com>
# Hence we use m.__send__(tree).domain
# r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue
r = false
end
record.errors[attribute] << (options[:message] || "is invalid. Please enter xEMPLOYEENUMBER@a2z.ie, e.g. x12345678@a2z.ie") unless (r && s)
end
end
Wasn't exactly what I wanted, but is somewhat.
Ref: https://github.com/plataformatec/devise/wiki/How-to:-Use-a-custom-email-validator-with-Devise
Used an email validator Ruby file instead.
Using Devise as well, if that helps.
In user.rb, add:
validates :email, :presence => true, :email => true
Create a validators
folder in models. Then create email_validator.rb in said folder and add this to it:
(app/models/validators/email_validator.rb) :
require 'mail'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
begin
m = Mail::Address.new(value)
# We must check that value contains a domain, the domain has at least
# one '.' and that value is an email address
r = m.domain.present? && m.domain.match('.') && m.address == value
s = m.domain.present? && m.domain.match('@a2z.ie') && m.address == value
# Update 2015-Mar-24
# the :tree method was private and is no longer available.
# t = m.__send__(:tree)
# We need to dig into treetop
# A valid domain must have dot_atom_text elements size > 1
# user@localhost is excluded
# treetop must respond to domain
# We exclude valid email values like <user@localhost.com>
# Hence we use m.__send__(tree).domain
# r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue
r = false
end
record.errors[attribute] << (options[:message] || "is invalid. Please enter xEMPLOYEENUMBER@a2z.ie, e.g. x12345678@a2z.ie") unless (r && s)
end
end
Wasn't exactly what I wanted, but is somewhat.
Ref: https://github.com/plataformatec/devise/wiki/How-to:-Use-a-custom-email-validator-with-Devise
answered Mar 25 at 12:39
TattooedJoeyTattooedJoey
185 bronze badges
185 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336290%2fembedded-ruby-form-validating-email-with-specific-domain%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try
:validation => /Axd8@a2z.iez/
– Wiktor Stribiżew
Mar 25 at 11:00
If
:validation
does not work, try replacing it with:pattern
– Wiktor Stribiżew
Mar 25 at 11:06
@WiktorStribiżew
:validation => /Axd8@a2z.iez/
did not work.:validation => '/Axd8@a2z.iez/'
did not work.:pattern => /Axd8@a2z.iez/
did not work.:pattern => '/Axd8@a2z.iez/'
did not work. :(– TattooedJoey
Mar 25 at 12:06
Do not put the regex inside single quotes, it will never work. So, the problem is not just with regex, you need to fix your code.
– Wiktor Stribiżew
Mar 25 at 12:07
1
@WiktorStribiżew I tried both with and without, none worked.
– TattooedJoey
Mar 25 at 12:08