Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBScript FAQ

String Manipulation

How do I check for certain characters and removing spaces by onpnt
Posted: 18 Jun 02

just another validation for reading form values.
I see a lot of questions beiong asked regarding these two methods in VBscript.
Checking for characters and getting rid of spaces.
The script is fairly easy to chagne to only perform one or the either or leave as is for both.
I gathered this code from others and myself to create the shortest easiest one I could come up with.
Happy Coding!

<HEAD><TITLE>Simple Validation</TITLE>
Sub Validate()
Dim Illchars, charcnt, banned, valid, inputvalue
' add characters to the Illchars var within the quotes
Illchars = "'^\/()#~<>|`ΒΌ:;!@$*+=%"    
valid = True
inputvalue = form1.Text1.value

'check for any value
    if inputvalue = "" or inputvalue = null then
alert "please make a entry for submission", vbOK
exit sub
end if

' trim the spaces left and right
inputvalue = Trim(Replace(inputvalue, " ", ""))

For charcnt = 1 to Len(Illchars)
  banned = Mid(Illchars, charcnt, 1)
  If InStr(inputvalue, banned) > 0 Then
    valid = False
    Exit For
  End If

If Not valid Then
  Str = ""
MyVar = MsgBox ("You have entered characters not valid.  Please try again!")
    Exit Sub
End If

Dim TheForm, MyVar
'replace spaces...
Do While InStr(1, TheForm, " ")
  TheForm = Replace(TheForm, " ", "")
MyVar = MsgBox ("Here it is without spaces, as long as you made it this far" & TheForm)
End Sub

<H3>Simple Validation</H3><HR>
<form Name="form1">

<input TYPE="TEXT" name="Text1" SIZE="30">
<input TYPE="button" name="Submit" VALUE="Submit" onClick="Validate()">

Back to VBScript FAQ Index
Back to VBScript Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close