Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator#regular expression #16

Merged
merged 4 commits into from
Aug 21, 2017
Merged

Validator#regular expression #16

merged 4 commits into from
Aug 21, 2017

Conversation

Flixow
Copy link
Contributor

@Flixow Flixow commented Aug 17, 2017

No description provided.

@codecov-io
Copy link

Codecov Report

Merging #16 into devel will increase coverage by 0.2%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##            devel      #16     +/-   ##
=========================================
+ Coverage   93.88%   94.09%   +0.2%     
=========================================
  Files           5        5             
  Lines         507      525     +18     
=========================================
+ Hits          476      494     +18     
  Misses         31       31

README.md Outdated
@@ -37,7 +38,8 @@ const rules = {
username: 'required|unique:users,username',
email: 'required|email',
age: 'required|numeric|min:18',
gender: 'in:male,female'
gender: 'in:male,female',
phoneNumber: 'regex:[0-9]{3} ?-?[0-9]{3} ?-?[0-9]{3}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test this with ,. It's used to separate parameters. If you get more that 1 parameter then you need to join parameteres with ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there is only 1 parameter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can use , in regex for example to match date 10th January, 2015. If you use , in regex then you might end up with 2 parameters

@@ -95,3 +95,9 @@ export function validateAlpha(attribute, value) {
export function validateAlphaNum(attribute, value) {
return (typeof value === 'string' || typeof value === 'number') && is.alphaNumeric(value)
}

export function validateRegex(attribute, value, parameters) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/messages.js Outdated
@@ -20,5 +20,6 @@ export default {
integer: 'The :attribute must be an integer.',
accepted: 'The :attribute must be accepted.',
alpha: 'The :attribute may only contain letters.',
alpha_num: 'The :attribute may only contain letters and numbers.'
alpha_num: 'The :attribute may only contain letters and numbers.',
regex: 'The :attribute must match to the format.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/*
* Regular Expression
* ----------------------------------------------------- */
describe('#regular_expression', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -95,3 +95,9 @@ export function validateAlpha(attribute, value) {
export function validateAlphaNum(attribute, value) {
return (typeof value === 'string' || typeof value === 'number') && is.alphaNumeric(value)
}

export function validateRegex(attribute, value, parameters) {
const regex = parameters[0] ? new RegExp(`${parameters[0]}`) : undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule should require just 1 parameter:

this.requireParameterCount(1, parameters, 'regex')

@codecov-io
Copy link

Codecov Report

Merging #16 into devel will increase coverage by 0.35%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##            devel      #16      +/-   ##
==========================================
+ Coverage   93.88%   94.23%   +0.35%     
==========================================
  Files           5        5              
  Lines         507      538      +31     
==========================================
+ Hits          476      507      +31     
  Misses         31       31

if (is.not.string(value) && is.not.number(value)) {
return false
}
const regex = parameters[0] ? new RegExp(`${parameters[0]}`) : undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.requireParameterCount will throw error if parameters[0] doesn't exit so this check is useless.

const regex = new RegExp(`${parameters[0]}`)

should be enough

@eyedea-io eyedea-io deleted a comment from codecov-io Aug 18, 2017
@eyedea-io eyedea-io deleted a comment from codecov-io Aug 18, 2017
@eyedea-io eyedea-io deleted a comment from codecov-io Aug 18, 2017
@eyedea-io eyedea-io deleted a comment from codecov-io Aug 18, 2017
@codecov-io
Copy link

Codecov Report

Merging #16 into devel will increase coverage by 0.35%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##            devel      #16      +/-   ##
==========================================
+ Coverage   93.88%   94.23%   +0.35%     
==========================================
  Files           5        5              
  Lines         507      538      +31     
==========================================
+ Hits          476      507      +31     
  Misses         31       31

1 similar comment
@codecov-io
Copy link

Codecov Report

Merging #16 into devel will increase coverage by 0.35%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##            devel      #16      +/-   ##
==========================================
+ Coverage   93.88%   94.23%   +0.35%     
==========================================
  Files           5        5              
  Lines         507      538      +31     
==========================================
+ Hits          476      507      +31     
  Misses         31       31

@Flixow Flixow merged commit 71da133 into devel Aug 21, 2017
@Flixow Flixow deleted the validator#Regular_Expression branch August 21, 2017 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants