Yii2 rule which would allow all the letters (including special ones), but without special characters?

↘锁芯ラ 提交于 2019-12-24 07:41:09

问题


I have a problem here. My username rule allowing to enter only letters without special characters, but could someone help me to make that it would allow letters (including special letters), but without special characters?

F.e:

Test - good, Tęęęst - good, Test2 - bad.

My rule is:

['username', 'match',
   'pattern' => '/[a-z]+$/',
]

Thanks for any help


回答1:


Use this but remember it does not work on the client side since JavaScript does not support unicode regex flags (at least without special plugins):

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

This allows letters (in all languages) only.



来源:https://stackoverflow.com/questions/43469793/yii2-rule-which-would-allow-all-the-letters-including-special-ones-but-withou

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!