It is very easy, you can use right function
If Right(yourstring,5) = "-1234" Then
.....
End If
If UCase(Right(yourstring, 4)) = ".COM" Then
....
End If
danny
Main Topics
Browse All TopicsHi, I need some help with string validation.
I need to perform a test on a couple of strings one to see if holds "-1234" the last 5 carecters of a phone# and another string to see if it holds ".com".
Any help would be most appreciated!
TIA
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Let c$ be the string to be tested:
1. to test for ".com" at the end
' Test is done case sensitive, i.e. ".COM" will not match ".com"
if right$(c$,4) = ".com" then
' success
else
' fail
endif
' change the condition not to be case sensitive to
if UCase$(Right$(c$,4)) = ".COM" then
2. to test for c$ contain -1234 (minus followed by 4 digits) at the end
Dim tail as String
dim ok as boolean
Dim i as integer
' Assume the check failed
ok = False
' get the 5 last chars
tail = Right$(C$,5)
' first check: the tail must be at least 5 chars long
if len(tail) = 5 then
' if so, the first char must be a minus
if left$(tail,1) = "-" then
' check last four for being digits
ok = true
for i = 2 to 5
ok = ok and is_digit(mid$(tail,i,1)
next i
endif
endif
' if ok=TRUE at this point, c$ contains a minus followed by 4 digits at the end:
if ok then
' success
else
' failure
endif
the function is_digit must be defined as follows:
private function is_digit ( c as string ) as boolean
is_digit = left$(c,1) >= "0" and left$(c,1) <= "9"
end function
This question was awarded, but never cleared due to the JSP-500 errors of that time. It was "stuck" against userID -1 versus the intended expert whom you awarded. This corrects the problem and the expert will now receive these points; points verified.
Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them. If you are an EE Pro user, you can also choose Power Search to find all your open questions.
This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
http://www.experts-exchang
http://www.experts-exchang
Thank you,
Moondancer
Moderator @ Experts Exchange
Business Accounts
Answer for Membership
by: Edward98Posted on 1999-10-04 at 01:57:11ID: 2096030
Edited text of question.