0

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?

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

That forward-slash in the OP's regex should have been a backslash, and the square brackets are redundant.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.