sean sean - 1 year ago 110
C# Question

How to get exact regex for accepting Number with alphabet only?

Hi I tried to get the exact regex for matching Number with alphabet only,
I tried this

Regex.IsMatch("1111", @"^[a-zA-Z0-9]+$")

but the output is true.

Here is what I want output

12345678 -> False
abcdefgh -> False
1234abcd -> True
1234ABCD -> True

Answer Source

Try the following positive lookahead matching expression:


This asserts that both grouped expressions are true and returns the full string on match.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download