Text Verifying

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

Simon:
copy this code in the 'Click event' of a button.
I'm not sure what your setup is so I'm assuming for now
that your testing a textBox with code behing a button.

The code:
If IsNumeric(txttest.Value) Then
MsgBox "This text only as numbers."
Else
MsgBox "This text as a mixture of alpha an numeric
characters."
End If
The 'isNumeric' is the key. It lets you know right away if
the text entered in a certain text boxe is numeric or not.

Hope this helps, are gives you at least a couple of ideas
on How to proceed...

PAtrick
-----Original Message-----
Hi,
I have a text box of text datatype. I want to make sure
that whatever the users key in is 10 characters consisting
of only 0123456789. I also want to keep the datatype of
this text box as text. Anybody has any idea or codes to
accomplish this?
 
Patrick said:
copy this code in the 'Click event' of a button.
I'm not sure what your setup is so I'm assuming for now
that your testing a textBox with code behing a button.

The code:
If IsNumeric(txttest.Value) Then
MsgBox "This text only as numbers."
Else
MsgBox "This text as a mixture of alpha an numeric
characters."
End If
The 'isNumeric' is the key. It lets you know right away if
the text entered in a certain text boxe is numeric or not.

Hope this helps, are gives you at least a couple of ideas
on How to proceed...

that whatever the users key in is 10 characters consisting
of only 0123456789. I also want to keep the datatype of
this text box as text. Anybody has any idea or codes to
accomplish this?


Be careful here, IsNumeric will match anything that can be
converted to a numeric type. This includes numbers with
minus signs, decimal points (in whatever your Loacale
setting specifies) along with all the scientific notations.
E.g.
IsNumeric(-1.2D+4) will be True

I propose that you use this expression in the text box's
Before Update event:

If Len(txttest) = 10 And Not (txttest Like "*[!0-9]*") Then
MsgBox "Try again"
Cancel = True
End If

Note that if all you want to do is check for decimal digits
with out regard to the length of 10, then you could just set
the text box's Validation Rule property to:

Not Like "*[!0-9]*"

and place your message in the Validation Text property.
 
Back
Top