R
R
Rodion Gashé2010-12-28 12:35:45
Regular Expressions
Rodion Gashé, 2010-12-28 12:35:45

Regular expression does not work correctly

On the one hand, everything is eerily trite - you need to allow the user to enter the first and last name in different fields, the conditions are Latin or Cyrillic, dot, space.
a-zdoes not skip the entire Cyrillic alphabet and the parameter ialso does not work with it, moreover, a-z does not represent the entire range of Cyrillic.

I did it tritely: /^([a-zA-Z \.\-]{1,20}|[абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ \.\-]{1,20})$/
Everything is cool, but there are situations when this bastard does not take what he needs, and specifically the name "Phoenician" - and eats it in parts, completely - no!

The only thing I do before checking is to process the received data with the function trim(), but the situation does not change even if it is removed.

Help, brothers and sisters!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
dsn13, 2010-12-28
@zorba_buddha

In PHP in UTF-8, you must use the u modifier Manual
excerpt:
u (PCRE_UTF8)
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern has been checked since PHP 4.3.5.
The expression becomes /^([az \.\-]{1,20}|[a-yayo \.\-]{1,20})$/ui

@
@icoder, 2010-12-28
_

Grenades, you have the wrong system. In .NET, the pattern works for "Phoenician", just checked. Most likely a bug in the code, some left character is missing somewhere.

@
@icoder, 2010-12-28
_

And ^([a-zA-Z \.\-]{1,20}|[a-zA-Z \.\-]{1,20})$ works great too.

H
Hint, 2010-12-28
@Hint

The point in enumerations does not need to be escaped, and the hyphen at the end too (but only if it is at the end).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question