Darren Darren - 1 year ago 66
C# Question

.Net Multiline Regex expression to restrict to integers

I am having a problem with a very simple regular expression.

I want to restrict the entry in a multi-line TextBox to just integers. The regular expression I have works fine in single line mode (for a single line TextBox, not using multiline option), but allows alpha characters to creep in when in multiline mode, but only once a new line has been entered.

My code (C#) is something like:

Regex regExpr = new Regex("^(\d*)$", RegexOptions.Multiline)
return regExpr.IsMatch(testString);

I want the following examples to be valid:




I want the following to be invalid




Thanks in advance.

Answer Source

What about

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