G
Guest
I want to check the text in a text box once the user tabs out of textbox, for
number only.
number only.
Mike L said:I want to check the text in a text box once the user tabs out of textbox,
for
number only.
Brendan Grant said:Try these two functions. The first tells you if the string passed in is a
number (int or float), while the second just tells you if it is an integer.
Regexes are very powerful, when used in the right place - but I believe
in this case it's like boarding an aeroplane in order to travel a
hundred metres.
Brendan Grant said:Code readability is always good, however there are times when performance is
more important than readability, and with extensive testing one can
dramatically reduce the risk of such a complicated regular expression from
causing you issues.
While using a Parse() may be simpler and more readable, I disagree that it
is more efficient.
Usage of either depends on which side you want to pay the
penalty of an unparseable value.
If it is a parseable value being passed in, then yes, Parse() faster, an
order of magnitude faster in the best case. On the other hand, if a lot of
invalid values are being dealt with, using the Regex method can be in the
best case ~50 times faster than Parse().