Skip to content

Instantly share code, notes, and snippets.

@hesco
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hesco/0dc7290a83f845657e83 to your computer and use it in GitHub Desktop.
Save hesco/0dc7290a83f845657e83 to your computer and use it in GitHub Desktop.
Mojolicious::Validator->like() question:
Why does this work:
$validation->required('instructors.fname')->size(1,35);
But this does not:
$validation->required('instructors.fname')->size(1,35)->like(qr/^[\w]$/);
My test is a count(*) on one of the effected tables.
With the former validation test in place, the count increments.
Roll the latter version into place and restart the app,
and the count does not increment.
What am I missing here please?
This:
->like(qr/^[\w]$/)
fails in unexpected ways (ways in which I think the check should pass),
although these:
->like($RE{Email}{Address}),
->like(Number::Phone::US::get_regex(), and
->like($RE{zip}{US})
all seem to work just fine.
@mjemmeson
Copy link

/^[\w]$ only matches a single character - is that what you want?
Also it's an unnecessary use of a character class ([ ... ])

I think you mean this: /^\w+$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment