Yahoo Username Regex

穿精又带淫゛_ 提交于 2019-12-20 12:36:12

问题


I need a (php) regex to match Yahoo's username rules:

Use 4 to 32 characters and start with a letter. You may use letters, numbers, underscores, and one dot (.).


回答1:


/^[A-Za-z](?=[A-Za-z0-9_.]{3,31}$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/

Or a little shorter:

/^[a-z](?=[\w.]{3,31}$)\w*\.?\w*$/i



回答2:


/[a-zA-Z][a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*/

And check if strlen($username) >= 4 and <= 32.




回答3:


A one dot limit? That's tricky.

I'm no regex expert, but I think this would get it, except for that:

[A-Za-z][A-Za-z0-9_.]{3,31}

Maybe you could check for the . requirement separately?




回答4:


Using lookaheads you could do the following:

^(?=[A-Za-z](?:\w*(?:\.\w*)?$))(\S{4,32})$

Because you didn't specify what type of regex you needed I added a lot of Perl 5 compatible stuff. Like (?: ... ) for non-capturing parens.

Note: I added the missing close paren back in.



来源:https://stackoverflow.com/questions/168956/yahoo-username-regex

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