The Wayback Machine - https://web.archive.org/web/20200908045251/https://github.com/go-playground/validator/issues/525/
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

Validate oneof with values containing space #525

Open
muhammadkholidb opened this issue Oct 1, 2019 · 3 comments
Open

Validate oneof with values containing space #525

muhammadkholidb opened this issue Oct 1, 2019 · 3 comments

Comments

@muhammadkholidb
Copy link

@muhammadkholidb muhammadkholidb commented Oct 1, 2019

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

Is it possible to use oneof validation with values containing space character? Tried with single quote but it did not seem to work.

Code sample, to showcase or reproduce:

type Data struct {
    Status string `json:"status" validate:"required,oneof='Awaiting Verification' 'Verified' 'Failed Verification'"`
}
@deankarn
Copy link
Contributor

@deankarn deankarn commented Oct 23, 2019

@muhammadkholidb no, unfortunately, this isn't supported for oneoff at the moment.

As a workaround for now though is you can register your own custom validation function which accomplishes the same thing :)

@JonathanWThom
Copy link
Contributor

@JonathanWThom JonathanWThom commented Nov 16, 2019

Hello 👋 , I'm going to take a crack at this.

JonathanWThom added a commit to JonathanWThom/validator that referenced this issue Nov 17, 2019
* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

Resolves go-playground#525.
JonathanWThom added a commit to JonathanWThom/validator that referenced this issue Nov 17, 2019
**Make sure that you've checked the boxes below before you submit PR:**
- [ ] Tests exist or have been written that cover this particular change.

Change Details:

* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

@go-playground/admins
JonathanWThom added a commit to JonathanWThom/validator that referenced this issue Nov 17, 2019
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular change.

Change Details:

* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

@go-playground/admins
JonathanWThom added a commit to JonathanWThom/validator that referenced this issue Nov 17, 2019
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular change.

Change Details:

* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

@go-playground/admins
JonathanWThom added a commit to JonathanWThom/validator that referenced this issue Nov 17, 2019
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular change.

Change Details:

* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

@go-playground/admins
JonathanWThom added a commit to JonathanWThom/validator that referenced this issue Nov 17, 2019
Fixes Or Enhances go-playground#525.

**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular change.

Change Details:

* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

@go-playground/admins
@fr3fou
Copy link

@fr3fou fr3fou commented Jan 21, 2020

Isn't this closed by #541

fairyhunter13 added a commit to fairyhunter13/validator that referenced this issue Jul 12, 2020
Fixes Or Enhances go-playground#525.

**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular change.

Change Details:

* Adds the ability to match on space separated strings when using the
`oneof` validation. Space separted strings must be surrounded by single
quotes to be validated as one string. For example:

```
oneof='Awaiting Verification' 'Verified' 'Failed Verification'
```

passes validation for a field that is exactly `Failed Verification`
(though just `Failed` would...fail).

@go-playground/admins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.