0
votes

I have this expression:

'/^([\p{L}\p{Mn}\p{Pd}\'\x{2019}]+|\d+)(\s+([\p{L}\p{Mn}\p{Pd}\'\x{2019}]+|\d+))*$/u'

It's goal is to match names and numbers like "6 de diciembre" or "Mariana de Jesús" (using numbers and unicode characters.

The issue is that it also matches typos like: "6de diciembre" [1]. Mixing numbers and letters in the same word should not be allowed (no, we have not expression like "6th" in this cases).

Question: What character classes should I use? I need digits and these unicode letters, but not mixed, not concatenated.

Notes: I posted a similar question regarding this topic before, but the issue was slightly different and cannot expect the same kind of answer.

[1] I can't believe I MUST clarify this point: typos should not be matched - unless explicitly said, a regex is to find an expected regular format in a string

1
if your input isn't regular (e.g. randomish/arbitrary), then you're going to have a very difficult time using a regular expression to match that randomness...Marc B
I didn't say it's randomish. I said it was a name, and gave you examples and an explanation: terms are separated by whitespaces, and are only numbers or (unicode letters|punct. symbols|hyphen). Doesn't sound random at all.Luis Masuelli
Typos must not be matched, of course. that's what a regex is used for.Luis Masuelli
Actually reading the question should lead you to conclude that 1. matched typos are an unexpected issue (I'm saying "issue" and explaining in present simple), 2. Gave examples of what I need to match. 3. Gave a bold text explaining what I shouldn't match. 4. Asked for a group of character classes telling that "need digits and these unicode letters, but not mixed, not concatenated".Luis Masuelli

1 Answers

0
votes

The expression works well. I had a totally different issue in which my validation handler was not called.

After a bit of experimentation I noticed that if I reduce the length of the validation handling function then the DRUPAL 7 form can use it as a handler, instead of silently discarding it. Yes, ladies and gentlemen, my handler was named toyotaec_form_webform_client_form_trabaja_con_nosotros_validate and assigned as:

`$form['#validate'][] = 'toyotaec_form_webform_client_form_trabaja_con_nosotros_validate';`.

Slicing the 'con_notros_' part in both sides made it work, and lead me to this conclusion.

.: Drupal has a(n absolutely senseless) limit for those identifiers, while PHP has not.
.: Drupal truncates the input when you assign it.
.: Drupal raises no error upon unexistent function (the truncated name does not exist as a function).

Rantful (but logic) conclusion: For this and many previous issues I conclude that drupal sucks.