Custom User Fields - Field Verification

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?

1 Like

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.

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.

1 Like

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.

1 Like

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.

1 Like

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.

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

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.

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).

Having validation would be incredibly helpful - especially so for phone numbers which people just don’t seem to be able to get right with the + thingo at the front. Yes, we can just tidy up the database but that is a pain in the butt.

1 Like

Couldn’t agree more. as long as you can verify fields based on format, length charcter, even allowing a regex that a field has to match, means you know you’re getting the right type of data so that api scripts can handle it without error.

Apologies for the lateness of the hour on this one - but for anyone scouring Meta to try and find out how to validate any custom fields you might’ve added, I thought it’d be worth mentioning how to do this with a plugin.

In your plugin.rb, use the validate method on User. You can then poke at your custom fields and set an error if any are invalid:

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

nb. the :my_cool_validation_method symbol can be anything you want, but should be unique within the context of the User model.

4 Likes