验证用户名 [英] Validating Username

查看:77
本文介绍了验证用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码验证用户名正常工作

展开 | 选择 | Wrap | 行号

解决方案

无法理解您的问题?


你希望你的正则表达式接受什么并且不接受?


也许我们可以帮你创建一个新的。


在这种情况下#符号和#符号后面的内容被忽略。所以在这种情况下,用户名只读为abc而不是abc#123



正则表达式不是问题。


看来你提交你的用户名是ajax而不是在提交之前没有 encodeURIComponent()


另外,如果你提交你的用户名为GET变量,通过URL,#字符及其后面的任何内容将被浏览器解析为锚名称。


如果是这种情况,请尝试 urlencode urldecode 功能。


i have used the following code to validate the username it is working fine

Expand|Select|Wrap|Line Numbers

解决方案

Cannot understand your problem?

What do you want your regex to accept and not accept?

Maybe we could help you create a new one.


in this case # sign and what comes after # sign is being ignored. so in this case the username is being read as abc ONLY and not abc#123

Its not a problem with regexp.

It seems like you are submitting your username with ajax and not doing encodeURIComponent() to it before submitting.


Also, if you are submitting your usernames as GET variables, via the URL, the # character and anything that follows it will be parsed as an anchor name by the browser.

If that is the case, try the urlencode and urldecode functions.


这篇关于验证用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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