I am trying to check if a user entered string contains a number in it. If it does i want to create an error. What is a simple way of doing this?
Check if string contains a number
-
-
-
Re: Check if string contains a number
How is the user entering the string?
-
Re: Check if string contains a number
Via a input box
-
-
Re: Check if string contains a number
Thanks but thats not really what i am after. My user is inputting a string
-
Re: Check if string contains a number
Thanks Dave but i found something i could use
then
-
Re: Check if string contains a number
Here's where a little bit of Linq can make life easier. This will return a boolean telling if there's at least one numeric character in the string.
(from items in inputString.ToCharArray Where Char.IsDigit(items)).Count <> 0
Dave -
Re: Check if string contains a number
Quote from grays;192686Thanks Dave but i found something i could use
then
Thanks grays - this is super helpful.
However, is there a way to modify it to be true if it contains any number except 0?
-
Re: Check if string contains a number
Here's where a little bit of Linq can make life easier. This will return a boolean telling if there's at least one numeric character in the string.
(from items in inputString.ToCharArray Where Char.IsDigit(items)).Count <> 0
DaveHi Dave, I hope you get this... 7 years later
Could you elaborate on how your code is supposed to work? I can't seem to make it work?
from items in inputString.ToCharArray WhereChar.IsDigit(items)).Count <> 0
how do i write this?
ie: x = from items in inputString.ToCharArray WhereChar.IsDigit(items)).Count <> 0 ??
-
LINQ doesn't work in VBA as far as I know. Seems overkill here anyway when a simple Like operator will work:
-
LINQ doesn't work in VBA as far as I know. Seems overkill here anyway when a simple Like operator will work:
You're absolutely right ! Works like a charm. So simple yet so efficient.
Thanks rory !
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!