Reputation: 4520
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
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
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
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