Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to test a text string against a given format

1 view
Skip to first unread message

Jacques

unread,
Mar 14, 2005, 2:38:14 PM3/14/05
to
Hi there,

I am dealing with text fields for which I need to control the format.
There are various fields and each of them as its specific format.

For example, if [Phone Numbers] must look like (+XXX YYYYYYYYY), I
want to make sure that the content matches it. I know I can parse the
string make appropriate tests but given the # of formats I have to
look after, I'm more looking for an object or something that would do
this job in one statement.

Thanks in anticipation for any help.

Jacques.-

Rick Rothstein

unread,
Mar 14, 2005, 2:58:00 PM3/14/05
to
> I am dealing with text fields for which I need to control the format.
> There are various fields and each of them as its specific format.
>
> For example, if [Phone Numbers] must look like (+XXX YYYYYYYYY), I
> want to make sure that the content matches it. I know I can parse the
> string make appropriate tests but given the # of formats I have to
> look after, I'm more looking for an object or something that would do
> this job in one statement.

Look into using the Like operator (check out VB's help files for the
various formatting checks it can make).

I'm not sure of what the significance of you using "X" and "Y" in your
sample, I thought they are all digits, but I think this would do what
you want for phone numbers...

If YourPhoneNumberAsText Like "(+### #########)" Then
' Phone number format is valid
Else
' it not valid.
End If

Rick - MVP
Sign up now to help keep VB support alive -
http://classicvb.org/petition


Jacques

unread,
Mar 21, 2005, 3:21:19 PM3/21/05
to
Thanks Rick - I'll have a look at that & let you know (X and Y were
both numbers indeed)
0 new messages