Check regex for letters numbers and underscore characters

Jean Tehhe

I tried to check if a string Name contains letters, numbers, and underscore character with the following code without success, any idea of what I miss here?

var regex = new Regex(@"^[a-zA-Z0-9]+$^\w+$");

        if (regex.IsMatch(Name) )

....

in addtion when I tried with the following code, I got a parsing error

"^[a-zA-Z0-9\_]+$" - Unrecognized escape sequence \_.

Var regex = new Regex(@"^[a-zA-Z0-9\_]+$");
Jerry

The regex should be:

@"^[a-zA-Z0-9_]+$"

You don't need to escape the underscore. You can also use the Regex.Ignorecase option, which would allow you to use @"^[a-z0-9_]+$" just as well.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Regex - Escape escape characters

来自分类Dev

Replacing characters in a regex

来自分类Dev

How to check if a substring contains all of the letters in "apple"

来自分类Dev

如何使用 RegEx 解析 __Underscore Delimited__ 值?

来自分类Dev

Implementing regex in comma separated numbers

来自分类Dev

REGEX获得“ any_characters((number,number))”

来自分类Dev

Regex: How to match sequence of SAME characters?

来自分类Dev

Adding several special characters to existing regex

来自分类Dev

Javascript regex that matches dot as punctuation only, no numbers

来自分类Dev

Regex - Match all numbers until character

来自分类Dev

Php: regex get all numbers before colon

来自分类Dev

FuzzyWuzzy 错误:StringProcessor.replace_non_letters_non_numbers_with_whitespace(s)

来自分类Dev

Regex pattern to find n non-space characters of x length after a certain substring

来自分类Dev

Underscore.js核心

来自分类Dev

$ q许诺与Underscore _each

来自分类Dev

在ReactJS上使用Underscore

来自分类Dev

反编译_underscore模板

来自分类Dev

Elegant way to use regex to match order-indifferent groups of characters (in a substring) while limiting how may times a given character can appear?

来自分类Dev

“ double underscore”和“ underscore x”有什么区别?

来自分类Dev

“ double underscore”和“ underscore x”有什么区别?

来自分类Dev

如何使jQuery与Underscore配合使用?

来自分类Dev

如何安装underscore.js?

来自分类Dev

不能要求CasperJS使用Underscore

来自分类Dev

Underscore groupBy using server data

来自分类Dev

Underscore.js嵌套分组

来自分类Dev

Underscore.js反跳

来自分类Dev

Underscore.js如何计算

来自分类Dev

安装Underscore类型时出错

来自分类Dev

Underscore.js模板编译

Related 相关文章

热门标签

归档