Remove Beginning and Ending Spaces ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

REMOVE BEGINNING AND ENDING SPACES

Let's face it. As long as people manually enter data, there are bound to be typos in your data. One common error is when a user adds extra spaces at the beginning or end of a form field. So how do you stop this?

First, you create a form.asp page and copy the code below:

<form name="YourFormName" method="Post" action="confirm.asp">
<table>
<tr><td>Email: </td>
<td><input type="text" name="Email" size="50"></td></tr>
<tr><td>First Name: </td>
<td><input type="text" name="FirstName" size="50"></td></tr>
<tr><td>Last Name: </td>
<td><input type="text" name="LastName" size="50"></td></tr>
<tr><td>Subject: </td>
<td><input type="text" name="Subject" size="50"></td></tr>
<tr><td>Comments: </td></tr>
<tr><td><textarea cols="50" name="Comments" ></textarea></td></tr>
</table>

<input type="submit" name="Submit" value="Submit">
</form>

Then, you use the TRIM function in your confirm.asp page to remove any spaces:

<%
DIM strEmail, strFirstName, strLastName, strSubject, strComments
strEmail = TRIM(Request.Form("Email"))
strFirstName = TRIM(Request.Form("FirstName"))
strLastName = TRIM(Request.Form("LastName"))
strSubject = TRIM(Request.Form("Subject"))
strComments = TRIM(Request.Form("Comments"))
%>

The TRIM() function will remove any extra spaces from the beginning and end of each form field here, which insures better consistency within your database. If you are only concerned with removing spaces from the left or right side of the text, you could alternatively use LTRIM() or RTRIM() respectively. That's it, TRIM away!

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
09 May 2008