0

I have a problem here. I know there were a lot of questions related to this, but I couldn't find any useful information. I need to write regular expression which would allow for user to enter just only letters in all the languages without special characters (f.e #@#%^&43) and etc.

I've tried this, but this expression doesn't allow to enter any letters or special characters:

/^\p{L}+$/u 

And this: this allows to enter just only letters, but without ąčęėįš :(

/[a-z]+$/

My rule is:

['name', 'match',
    'pattern' => '^\p{L}+$',
],

Thank you for any help

user7435747
  • 417
  • 2
  • 5
  • 11
  • See [Yii2 rule which would allow all the letters (including special ones), but without special characters?](http://stackoverflow.com/questions/43469793/yii2-rule-which-would-allow-all-the-letters-including-special-ones-but-withou). The `/^\p{L}+$/u` will validate any string that has 1 or more letters. – Wiktor Stribiżew Apr 19 '17 at 08:12
  • As you can see, my used regular expressions is exact as in that post, today i've tried that, but it didn't worked, so – user7435747 Apr 19 '17 at 08:13
  • Did you run the validation on the *server* side? It is written in the answer there you cannot pass this pattern to the JS regex engine. – Wiktor Stribiżew Apr 19 '17 at 08:13
  • Ehm, nah, haven't done that yet. Could you tell me how the validation should be done? – user7435747 Apr 19 '17 at 08:23
  • "If you want to turn off client-side validation completely, you may configure the `yii\widgets\ActiveForm::$enableClientValidation` property to be false. You may also turn off client-side validation of individual input fields by configuring their `yii\widgets\ActiveField::$enableClientValidation` property to be false. When *enableClientValidation* is configured at both the input field level and the form level, the former will take precedence." ([source](http://www.yiiframework.com/doc-2.0/guide-input-validation.html)) – Wiktor Stribiżew Apr 19 '17 at 08:25

1 Answers1

0

See http://www.pcre.org/original/doc/html/pcrepattern.html

This has a list of all options for \p, pick the one that suits your need, or combine them like ^[\p{L}\p{N}]+$. Valid for server-side PCRE (PHP), not frontend (JS).

Doqnach
  • 372
  • 1
  • 8