TheGateKeeper
TheGateKeeper

Reputation: 4520

Numeric textbox with regex

im trying to do a numeric textbox in asp.net using regex, and came up with:

^[^\s]+[/d]+[^\s]$

I want it to disallow leading/trailing whitespace, and allow only numbers.

Any clue why it doesnt work?

Upvotes: 0

Views: 366

Answers (3)

yangrenyong
yangrenyong

Reputation: 64

Since you want to disallow whitespace and other characters, why don't you try ^\d+$ and inverse the way of evaluation in your code?

Upvotes: 1

Kaivosukeltaja
Kaivosukeltaja

Reputation: 15735

Your regex currently means "anything but whitespace, followed by slashes and d-letters, followed by one more of anything but whitespace". A simple ^\d+$ is sufficient.

Upvotes: 1

Narendra Yadala
Narendra Yadala

Reputation: 9664

You can try this ^\d+$. \d matches digits. The one you wrote does not work because you are using /d instead of \d.

Upvotes: 5

Related Questions