如何验证应该以字符开头,下划线然后是字符的UserName? [英] How to validate UserName that should start with characters followed by underscore and then followed by characters?

查看:73
本文介绍了如何验证应该以字符开头,下划线然后是字符的UserName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何验证应以字符开头,下划线然后是字符的UserName?


谢谢...

How to validate UserName that should start with characters followed by underscore and then followed by characters??


Thanks...

推荐答案

尝试一下

try this

public bool IsAlphaNumericWithUnderscore(string input)
{
    return Regex.IsMatch(input, "^[a-zA-Z0-9_]+


"); }
"); }








or

bool result = input.All(c=>Char.IsLetterOrDigit(c) || c=='_');


您可以为此使用正则表达式.像这样的东西.
You can use the regular expression for this. something like this.
var regExp = new Regex("[a-zA-Z]+_[a-zA-Z]+");
Match match = regExp.Match(UserName);
if (!match.Success)
{
  //Invalidate.
  //return
}


这篇关于如何验证应该以字符开头,下划线然后是字符的UserName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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