用户名带有一个下划线,并且不应包含任何特殊字符 [英] username having one underscore and should not allow any special characters
本文介绍了用户名带有一个下划线,并且不应包含任何特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我的要求是使用一个带下划线的用户名,并且不允许使用任何特殊字符.我正在使用客户端验证,因此请帮助我使用正确的正则表达式.
例如:john_12john
提前谢谢..
Hello,
My requirement is to have a username which is having one underscore and should not allow any special characters.I am using client side validation so pls help me with the correct regex.
eg:john_12john
Thanks in advance..
推荐答案
试试rhis one
\ > http://stackoverflow.com/questions/9864444/how-to-block-special-characters [ ^ ]
Hi,
Try rhis one
\http://stackoverflow.com/questions/9864444/how-to-block-special-characters[^]
public bool IsAlphaNumericWithUnderscore(string input)
{
return Regex.IsMatch(input, "^[a-zA-Z0-9_]+
"); }
"); }
或
or
bool result = input.All(c=>Char.IsLetterOrDigit(c) || c=='_');
这篇关于用户名带有一个下划线,并且不应包含任何特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文