Removing the leading blank spaces from the field

Results 1 to 3 of 3

Thread: Removing the leading blank spaces from the field

  1. #1
    Join Date
    Dec 1969
    Posts
    119

    Default Removing the leading blank spaces from the field

    I want to collect data in text boxes, but I fear someone may just put in blank spaces. Certainly I don&#039t want a record to be created with blank field value. How can I do this? Can this be done at the time of reading variables from text box, or it is to be done at the time of record insertion?<BR>Please help.<BR>Arvind

  2. #2
    Join Date
    Dec 1969
    Posts
    511

    Default RE: Removing the leading blank spaces from the field

    When you read the form values in to your validation variables use the Trim command to remove and leading and following spaces.<BR><BR>MyVar = Trim(Request.Form("Name"))<BR>If MyVar = "" Then<BR> &#039Empty<BR>End If<BR><BR>You could mix this with client side validation to remove most of the validation checking and speed up the data entry for the user as they don&#039t have to wait for error messages to be returned fromt he server every time.<BR><BR>Hope that helps<BR><BR>Pete

  3. #3
    Join Date
    Dec 1969
    Posts
    1,013

    Default RE: Removing the leading blank spaces from the field

    I use this one to tell if a field is blank<BR> <BR>Data is the name of the control you pass to the function.<BR><BR>function isempty(data)<BR>{<BR>varString = data.value<BR>for (var i = 0; i &#060; varString.length; i++)<BR>{<BR>if (varString.substring(i,i+1) != " ") return(false);<BR>return(true);<BR>}<BR>return(tru e)<BR>} <BR><BR><BR>I use this to trim all leading and trailling blanks<BR>Phrase is a string <BR>function LTrim(phrase)<BR>{<BR>while (phrase.charAt(0)==" ")<BR>{<BR>phrase=phrase.substr(1,phrase.lengt h-1)<BR>}<BR>return(phrase)<BR>}<BR>function RTrim(phrase)<BR>{<BR>while (phrase.charAt(phrase.length-1)==" ")<BR>{<BR>phrase=phrase.substr(0,phrase.lengt h-1)<BR>}<BR>return(phrase)<BR>}<BR>function Trim(phrase)<BR>{<BR>phrase=LTrim(phrase)<BR>phras e=RTrim(phrase)<BR><BR>return(phrase)<BR>}<BR><BR> <BR><BR>Any question email me at ccorraliza@diamondtechnologies.com<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •