Reputation: 1357
I'm using the following regex for validation of numbers which is working fine.
Problem is that if you enter in the textbox some valid number and then press space, the expression is not valid anymore.
How should I ignore spaces at the end of the entered value by regex handling ?
@"^[0-9]+$"
Upvotes: 0
Views: 61
Reputation: 82534
There are at least 2 ways to solve this problem:
add \s*
to the regEx - @"^[0-9]+\s*$"
- it means any number of white
spaces of any kind are allowed after at least one digit
Use the regEx on the trimmed text of the textbox - regEx.IsMatch(TextBox.Text.Trim())
Upvotes: 0
Reputation: 11126
@"^[0-9]+\s*$"
like this you can make the space take zero or more spaces at the end.
*
is a quantifier made for this particular purpose
Upvotes: 1