question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to apply Regex validation to an array of strings

See original GitHub issue

Below is the code test the bug

var EmailSchema = new SimpleSchema({
    emails: {
        type: [String],
        minCount: 1,
    optional: false,
        regEx: SimpleSchema.RegEx.Email
        }
});

isValid = EmailSchema.namedContext("myContext").validate({ emails: ['sdfsdfsf sd'] });
//isValid is false. 

isValid = EmailSchema.namedContext("myContext").validateOne({ emails: ['sdfsdfsf sd'] },"emails");
//isValid is true. I could be wrong but shouldn't "emails" validation be false? 

I’m probably missing something but is it possible to apply Regex validation to an array of strings as defined above?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
aldeedcommented, Mar 23, 2015

Use a full definition instead of the [String] shortcut.

emails: {
  type: Array,
  minCount: 1
},
'emails.$': {
  type: String,
  regEx: SimpleSchema.RegEx.Email
}
0reactions
emmanuelbuahcommented, Mar 28, 2015

Sounds good. Thanks.

On Sat, Mar 28, 2015, 7:50 AM Eric Dobbertin notifications@github.com wrote:

@emmanuelbuah https://github.com/emmanuelbuah, I think putting something like this in your form below your emails field will work.

{{#each invalidEmailFields}}

{{afFieldMessage name=this.name}}

{{/each}}

With helper

invalidEmailFields: function () { var c = AutoForm.getValidationContext(); if © { return _.select(c.invalidKeys(), function (key) { return key.name.indexOf(‘emails.’ === 0); }); } }

Either way, this is an autoform question, so I will close and you can post in the autoform repo if you still need help.

— Reply to this email directly or view it on GitHub https://github.com/aldeed/meteor-simple-schema/issues/304#issuecomment-87240320 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

what is javascript regex to validate an array of string value
I want to validate an array of a single element of type string using regex. The array should not be empty and should...
Read more >
How to apply Regex validation to an array of strings #304
var EmailSchema = new SimpleSchema({ emails: { type: [String], minCount: 1, optional: false, regEx: SimpleSchema.RegEx.
Read more >
How to apply regular expression on array of Strings(String[])
I am getting these in string[] ( String Array) parameter. In next action I need to display only below as a User Input...
Read more >
Regular Expression for array of numbers - Regex Tester
Match anything enclosed by square brackets. Find Substring within a string that begins and ends with paranthesis · Simple date dd/mm/yyyy · Blocking...
Read more >
Guide to Regular Expressions and Matching Strings in ...
In this guide, we'll take a look at the RegExp class and Regular ... In order to achieve this, you can pass an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found