[英]Regex to validate a username in react native
I don't know much regex and when it comes to username it becomes a little tricky, so I request from my fellow programmers to help me validate a username with respect to certain conditions.我不太了解正则表达式,当涉及到用户名时,它变得有点棘手,所以我请求我的程序员同事帮助我根据某些条件验证用户名。
Examples of valid and invalid usernames:有效和无效的用户名示例:
josh valid
乔希
valid
.josh_ invalid
.josh_
invalid
_josh. _乔什。
invalid
_josh_123.brad valid
_josh_123.brad
valid
josh brad invalid
乔什布拉德
invalid
I have already searched and the answer I find didn't quite help.我已经搜索过了,我找到的答案并没有太大帮助。 This is my regex for now:
这是我现在的正则表达式:
RegExp('^(?=[A-Za-z0-9._]{4,20}$)[^_.].*[^_.]');
Thanks in advance提前致谢
This can be achieved without any lookahead:这可以在没有任何前瞻的情况下实现:
/^\w[\w.]{2,18}\w$/
If you want to use RegExp
then use:如果你想使用
RegExp
然后使用:
var re = new RegExp("^\\w[\\w.]{2,18}\\w$");
Pattern Details:图案详情:
\\w
: is a shortcut for [a-zA-Z0-9_]
\\w
: 是[a-zA-Z0-9_]
的快捷方式^
: Start ^
: 开始\\w
: Match a word character \\w
: 匹配一个单词字符[\\w.]{2,18}
: Match 2 to 18 counts of word or dot characters thus making total length between 4 to 20 [\\w.]{2,18}
:匹配 2 到 18 个单词或点字符,从而使总长度在 4 到 20 之间\\w
: Match a word character \\w
: 匹配一个单词字符$
: End $
: 结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.