checking a textbox for spaces...

B

Brad Pears

How do you check for spaces in a text box? I can check for isnull(txtbox)
but what if the user presses space bar a few times? Also len(txtbox) = 0
does not work because spaces are something! What do you check for then?

Thanks,

Brad
 
G

Gerald Stanley

To eliminate any starting and closing spaces, use Trim e.g.
IsNull(Trim(txtBox)) should yield True if the user has entered nothing but
spaces.

Hope This Helps
Gerald Stanley MCSD
 
G

Graham Mandeno

Hi Brad

Do you want to allow spaces within the data entered - for example "Brad
Pears"?

If so, then use the Trim function to remove all leading and trailing spaces:
If Len(Trim(txtbox) & "") = 0 then ...

The & "" looks after the case where txtbox is Null, because in that case
Trim would return Null and Len(Null) is Null, not zero.

If you want to disallow spaces anywhere in the string, then use InStr:
If IsNull(txtbox) Or InStr(txtbox, " ") <> 0 Then ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top