# Uniform - more extensive validation questions

**URL:** <https://forum.getkirby.com/t/uniform-more-extensive-validation-questions/6440>\
**Category:** Questions\
**Tags:** v2\
**Created:** [January 28, 2017, 4:10pm UTC](https://forum.getkirby.com/t/uniform-more-extensive-validation-questions/6440 "2017-01-28T16:10:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luke/32/3083_2.png) [@Luke](https://forum.getkirby.com/u/Luke)\
**Post date:** [January 28, 2017, 4:10pm UTC](https://forum.getkirby.com/t/uniform-more-extensive-validation-questions/6440/1 "2017-01-28T16:10:11Z")

</div>

Hello (@mzur) and any others who may be able to help,

I’m looking to create a more thorough user registration using the uniform plugin that will ideally have some more advanced validation on fields, such as phone numbers, zipcodes, states, etc.

The uniform documentation doesn’t seem to have an extensive list of validation methods. The few I was able to extract while perusing it for answers were “required”, “email” and “num” and “in”.

Are these validation rules based entirely on he Kirby form field validation rules, meaning others like “match” would be available (i presume this would be my best bet for validating a telephone number)?

And if the Num works like this in Kirby:

```auto
if(v::num(1.0)) {
  echo 'Yay, valid!';
}

```

and like this in Uniform:

```auto
'attendees' => [
    'rules' => ['required', 'num'],
    'message' => 'Please enter a number of attendees',
],
'booth' => [
    'rules' => ['required', 'in' => [['6 sqm', '12 sqm', 'special']]],
    'message' => 'Please choose a booth size',
],

```

I presume a match would follow a similar conversion, sort of a blend of the two above:

```auto
if(v::match($value, '/[a-z0-9]+/')) {
  echo 'Yay, valid!';
}

```

to:

```auto
'phone' => [
    'rules' => ['required', 'match' => '/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/'],
    'message' => 'Please enter a valid phone number',
],

```

regex example sourced from [here](http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) because I’m not fluent in regex… just added some leading and trailing \ to the answer provided there, because otherwise I was getting an error otherwise (and that’s what kirby’s match had).

As I was typing this up, I ended up just testing it myself. And it does look like it work so far, testing various formatting of phone numbers I would encounter in a US only registration page. But I’m going to post this anyway in case it helps anyone else, and also because I’d like to encourage @mzur to update the documentation with a more extensive list/conversion of validation methods when he has time.

---

<div class="post-metadata">

**Author:** ![mzur](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@mzur](https://forum.getkirby.com/u/mzur)\
**Post date:** [January 28, 2017, 4:35pm UTC](https://forum.getkirby.com/t/uniform-more-extensive-validation-questions/6440/2 "2017-01-28T16:35:14Z")

</div>

The Uniform validation rules use Kirby’s [invalid](https://getkirby.com/docs/cheatsheet/helpers/invalid) helper internally. The invalid helper in turn uses the [validators](https://github.com/getkirby/toolkit/blob/adc1f778c4e61b01287772d044bb6ff1af073e67/lib/v.php#L51) of the Kirby Toolkit. You can use any of these to validate form fields. I’ll update the Uniform documentation to make that more clear.

You can also implement custom validators to do things like these:

```php
'phone' => [
    'rules' => ['required', 'phone'],
    'message' => 'Please enter a valid phone number',
],

```

Side note: Show your support for my [PR](https://github.com/getkirby/toolkit/pull/205) that implements improved error messages for the invalid helper 😉

**Edit:** The docs now [include links](https://kirby-uniform.readthedocs.io/en/latest/usage/#validation-rules) to the available validators and to the guide on how to implement custom validators. I _did_ mention the invalid helper there before, though 😜

---

<div class="post-metadata">

**Author:** ![Luke](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luke/32/3083_2.png) [@Luke](https://forum.getkirby.com/u/Luke)\
**Post date:** [January 28, 2017, 7:27pm UTC](https://forum.getkirby.com/t/uniform-more-extensive-validation-questions/6440/3 "2017-01-28T19:27:46Z")

</div>

Thank you for the incredibly prompt, and very helpful, response. I’ve given your PR a thumbs up emoji. I like the second item you listed with multiple error messages for each validation check. It’s not necessarily a requirement in my case, but if it was available I would certainly be using it opposed to my single “Please enter a valid phone number” error.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:52pm UTC](https://forum.getkirby.com/t/uniform-more-extensive-validation-questions/6440/4 "2025-02-06T16:52:52Z")

</div>

Archived on February 6, 2025, 4:52pm UTC


