# Custom User Fields - Field Verification

**URL:** https://meta.discourse.org/t/custom-user-fields-field-verification/109574
**Category:** Feature
**Created:** [2월 19, 2019, 5:59오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574 "2019-02-19T17:59:31Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![adambirds](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adambirds/32/131854_2.png) [@adambirds](https://meta.discourse.org/u/adambirds)
#### Post date: [2월 19, 2019, 5:59오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/1 "2019-02-19T17:59:32Z")

</div>

Unsure if I’ve missed it, but the custom User Fields, you can set a field type, bu is their anyway to verify on these fields, such as for a mobile number or via regex so we can verify against any data?

If not currently, could this be added?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2월 21, 2019, 2:08오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/2 "2019-02-21T14:08:05Z")

</div>

There isn’t much point in adding phone number verification. It’s easy for a bad actor to generate a bogus phone number with the right number of digits and highly annoying when a legitimate user has to guess what phone number format someone thinks is the right one.

---

<div class="post-metadata">

### Author: ![adambirds](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adambirds/32/131854_2.png) [@adambirds](https://meta.discourse.org/u/adambirds)
#### Post date: [2월 21, 2019, 2:10오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/3 "2019-02-21T14:10:35Z")

</div>

That was just an example of one field, we have multiple fields to store such as memberships. And it we need some sort of verification that the information is even remotely correct. Currently for a phone number you can enter text.

We should be able to use regex to verify these fields or they are pretty useless.

---

<div class="post-metadata">

### Author: ![adambirds](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adambirds/32/131854_2.png) [@adambirds](https://meta.discourse.org/u/adambirds)
#### Post date: [2월 23, 2019, 3:17오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/4 "2019-02-23T15:17:34Z")

</div>

Also, on the point of mobile numbers, yes they can be fake, but for our use case of the forum, its for their benefit that is correct. And being able to perform some sort of verification means that our scripts that would use them wouldn’t be affected by entering letters instead of numbers for example.

One the second point of different formats, that easy enough where you give the field a description field so you can let them know that. Verification of custom fields is a very basic requirement.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [2월 23, 2019, 6:37오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/5 "2019-02-23T18:37:54Z")

</div>

If you want that kind of detail consider an external membership platform and IdM.

This isn’t the kind of thing that discussion software should be doing.

---

<div class="post-metadata">

### Author: ![adambirds](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adambirds/32/131854_2.png) [@adambirds](https://meta.discourse.org/u/adambirds)
#### Post date: [3월 2, 2019, 9:17오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/6 "2019-03-02T21:17:10Z")

</div>

Again, the point isn’t what I want to do with it, but more the fact that custom fields should be able to be verified.

There is no point in them if you can’t somehow verify the data going into them.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [3월 2, 2019, 9:40오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/7 "2019-03-02T21:40:09Z")

</div>

How much do you verify the name and identity of your users?

---

<div class="post-metadata">

### Author: ![adambirds](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adambirds/32/131854_2.png) [@adambirds](https://meta.discourse.org/u/adambirds)
#### Post date: [3월 2, 2019, 9:45오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/8 "2019-03-02T21:45:59Z")

</div>

A lot, we’re a closed community. We are only able to verify on email at the moment compared to our current system, but as this can change on both sides, we want them to be able to enter a membership number and mobile and verify on both of those as well. At least if the verification of the field allows us to ensure the info entered is of the right type and length, our scripts using the API can handle the rest.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [3월 2, 2019, 9:48오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/9 "2019-03-02T21:48:38Z")

</div>

So you’re not talking about verifying anything, just validating that the data meets an expected format.

Discourse isn’t going to do this for you, you might be able to achieve validation with a plugin, but even then there’s nothing to prevent someone entering bad data in an expected format just to bypass said validation.

Your only real option is to look at something off-site or create a genuine incentive for users to provide real data. Right now you’re fixating on a symptom (not getting the data you want), not the root of the problem (giving users a real and compelling reason to provide it).

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [3월 15, 2020, 5:58오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/10 "2020-03-15T17:58:02Z")

</div>

검증 기능이 있다면 정말 도움이 될 것 같습니다. 특히 전화 번호는 앞의 ‘+’ 기호를 제대로 입력하지 못하는 경우가 많은데, 이런 상황에서 유용할 것입니다. 물론 데이터베이스를 정리할 수는 있지만, 그건 정말 귀찮은 일입니다.

---

<div class="post-metadata">

### Author: ![adambirds](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adambirds/32/131854_2.png) [@adambirds](https://meta.discourse.org/u/adambirds)
#### Post date: [4월 2, 2020, 10:40오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/11 "2020-04-02T22:40:17Z")

</div>

전적으로 동의합니다. 형식, 길이, 문자 종류에 기반하여 필드를 검증할 수 있고, 필드가 반드시 일치해야 하는 정규식까지 허용할 수 있다면, 올바른 유형의 데이터를 받고 있다는 것을 알 수 있으므로 API 스크립트가 오류 없이 이를 처리할 수 있습니다.

---

<div class="post-metadata">

### Author: ![snoopdouglas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snoopdouglas/32/186414_2.png) [@snoopdouglas](https://meta.discourse.org/u/snoopdouglas)
#### Post date: [8월 10, 2020, 1:25오후 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/12 "2020-08-10T13:25:33Z")

</div>

늦은 시간에 이 글을 올리는 점 양해 부탁드립니다. Meta에서 추가한 커스텀 필드를 어떻게 검증하는지 알아내려고 헤매고 계신 분들을 위해, 플러그인을 통해 이를 수행하는 방법을 언급할 가치가 있다고 생각했습니다.

`plugin.rb` 파일에서 `User`의 `validate` 메서드를 사용하세요. 그런 다음 커스텀 필드를 확인하고, 잘못된 값이 있으면 오류를 설정할 수 있습니다:

```ruby
require_dependency 'user'

validate User, :my_cool_validation_method do
  field = self.custom_fields['cool_tapes']
  if ! field.blank? && field.include?("bag of four grapes")
    self.errors[:cool_tapes] << "No rhymes allowed."
  end
end

```

참고로, `:my_cool_validation_method` 심볼은 원하는 무엇으로든 설정할 수 있지만, `User` 모델 컨텍스트 내에서 고유해야 합니다.

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [12월 18, 2021, 12:48오전 UTC](https://meta.discourse.org/t/custom-user-fields-field-verification/109574/13 "2021-12-18T00:48:04Z")

</div>

회원 가입 시 사용자 정의 필드를 검증하고, 사용자 프로필에서 수정할 때도 이 기능을 사용할 수 있을까요?

또한, 이 기능을 테마 컴포넌트에 어떻게 적용할 수 있을까요?
