Board index » Visual Studio » Checking Strings

Checking Strings

Visual Studio94
Im having one of those brain dead days today,



I carnt remember how to check a string to ensure that it

only contains the letters in the range a-z and nothing

else


-
 

Re:Checking Strings

Not "lwkd" Like "*[!a-z]*"

returns true and

Not "lwkd3" Like "*[!a-z]*"

returns false



"Peter Newman" <anonymous@discussions.microsoft.com>wrote in message

Quote
Im having one of those brain dead days today,



I carnt remember how to check a string to ensure that it

only contains the letters in the range a-z and nothing

else





-

Re:Checking Strings

THanks.. though im still struggling with one aspect



When some one enters a Telephone number i use the

validate function and use

If Not UserData(TelephoneNumber).Text Like "*[!0-9]*"

which works fine to check if only the numbers 0 - 9 are

present, however once i have formatted the data using



Format(number, "0## #### ####")



the validate fails





Quote
-----Original Message-----

Not "lwkd" Like "*[!a-z]*"

returns true and

Not "lwkd3" Like "*[!a-z]*"

returns false



"Peter Newman" <anonymous@discussions.microsoft.com>

wrote in message

news:08d201c3db66$9fbd3430$a601280a@phx.gbl...

>Im having one of those brain dead days today,

>

>I carnt remember how to check a string to ensure that

it

>only contains the letters in the range a-z and nothing

>else





.



-

Re:Checking Strings

Quote
When some one enters a Telephone number i use the

validate function and use

If Not UserData(TelephoneNumber).Text Like "*[!0-9]*"

which works fine to check if only the numbers 0 - 9 are

present, however once i have formatted the data using



Format(number, "0## #### ####")



the validate fails



That is because the formatted number has a character other than 0 to 9 in it

(the two blank spaces). If you validate the number before you format it, why

would you need to check it afterwards? I mean, if it is all digits before

you do the Format statement, it will (aside from the blank spaces being

added) be all digits afterwards also.



Rick - MVP





-

Re:Checking Strings

Peter,

Don't forget when you apply the formatting to the string you are adding

spaces into the it, so that it no longer contains just the characters

'0'-'9'.

So what you need to do is change your test slightly:



formattedNumber = Format(UserData(TelephoneNumber).Text , "0## #### ####")

If Not UserData(formattedNumber).Text Like "*[!0-9] *"



Note the space character between the ']' and the '*'



Cheers,



ChrisM





"Peter Newman" <anonymous@discussions.microsoft.com>wrote in message

Quote
THanks.. though im still struggling with one aspect



When some one enters a Telephone number i use the

validate function and use

If Not UserData(TelephoneNumber).Text Like "*[!0-9]*"

which works fine to check if only the numbers 0 - 9 are

present, however once i have formatted the data using



Format(number, "0## #### ####")



the validate fails





>-----Original Message-----

>Not "lwkd" Like "*[!a-z]*"

>returns true and

>Not "lwkd3" Like "*[!a-z]*"

>returns false

>

>"Peter Newman" <anonymous@discussions.microsoft.com>

wrote in message

>news:08d201c3db66$9fbd3430$a601280a@phx.gbl...

>>Im having one of those brain dead days today,

>>

>>I carnt remember how to check a string to ensure that

it

>>only contains the letters in the range a-z and nothing

>>else

>

>

>.

>





-

Re:Checking Strings

Quote
Don't forget when you apply the formatting to the string you are adding

spaces into the it, so that it no longer contains just the characters

'0'-'9'.

So what you need to do is change your test slightly:



formattedNumber = Format(UserData(TelephoneNumber).Text , "0## ####

####")

If Not UserData(formattedNumber).Text Like "*[!0-9] *"



Note the space character between the ']' and the '*'



The blank space character needs to be **inside** brackets, not outside;

otherwise, a text string like



UserData(formattedNumber).Text = "1x3 4567 8901"



will report incorrectly. Of course, the space character can't go in front of

the exclamation character or between the 0 and 9.



Rick - MVP





-

Re:Checking Strings

Oops,



Sorry Peter (and thanks Rick)



I had it the right way round when I was checking on my PC, then had a

brain-storm while writing my post!



I think I went to bed too late last night...



ChrisM



"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message

Quote
>Don't forget when you apply the formatting to the string you are adding

>spaces into the it, so that it no longer contains just the characters

>'0'-'9'.

>So what you need to do is change your test slightly:

>

>formattedNumber = Format(UserData(TelephoneNumber).Text , "0## ####

####")

>If Not UserData(formattedNumber).Text Like "*[!0-9] *"

>

>Note the space character between the ']' and the '*'



The blank space character needs to be **inside** brackets, not outside;

otherwise, a text string like



UserData(formattedNumber).Text = "1x3 4567 8901"



will report incorrectly. Of course, the space character can't go in front

of

the exclamation character or between the 0 and 9.



Rick - MVP









-