Yii2 规则允许所有字母(包括特殊字母),但没有特殊字符? [英] Yii2 rule which would allow all the letters (including special ones), but without special characters?

查看:38
本文介绍了Yii2 规则允许所有字母(包括特殊字母),但没有特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有问题.我的 username 规则只允许输入没有特殊字符的字母,但有人可以帮助我让它允许输入字母(包括特殊字母),但没有特殊字符?

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?

费:

测试 - 好,Tęęęst - 好,测试 2 - 不好.

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

我的规则是:

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

感谢您的帮助

推荐答案

使用这个但记住它在客户端不起作用,因为 JavaScript 不支持 unicode regex 标志(至少没有特殊插件):

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.

这篇关于Yii2 规则允许所有字母(包括特殊字母),但没有特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆