[RESOLVED]Large spaces with text inputs

Hey guys,

I have noticed on a web project I am working on that within my form I have text input fields. I have not coded them any different to how I normally would, only main difference is this application works off of a SQL Server not SQL Compact.

I am noticing when the data is being inserted in the database, there is quite a bit of space within the input – ie:                                 input here

Anything I may of done wrong or a cleansing method I can employ to ensure that such spaces are removed?

Cheers!

Hi,

Try trimming the space at ending and at start of a text using Trim() method at serverside.

for clientside you can employ a js function which trims the input on "onblur" event.  [ str = str.replace(/ /g,""); ]

raju dasa

Trim()

Would prefer to keep it server side, perhaps integrate it with my Request code (as it’s part of a form)..

However – what is the cause for this issue? Seems bizarre.. 

a-rad

I have text input fields.

Can you show those two inputs html markup?

Ashim Chatterjee

a-rad

I have text input fields.

Can you show those two inputs html markup?

Hey there,

Here is how the input is coded:

<div class="form-group">
    <label for="formTextField">Text Area</label>
    <input type="text" class="form-control" id="formTextField" placeholder="My Placeholder">
</div>

these are html controls , how you are getting these values in sever side ? (nothing unusual in these tags by the way)

<div class="form-group">
    <label for="formTextField">Text Area</label>
    <input type="text" class="form-control" id="formTextField" placeholder="My Placeholder"/>
</div>

The presence of trailing spaces in a text field suggests that your SQL Server column definition is using nchar() instead of nvarchar().

The former forces trailing spaces up to the defined length of the field.  

The latter  just stores the data as provided to the database, without adding any trailing spaces to fill up to the stated length

rrrsr7205

The presence of trailing spaces in a text field suggests that your SQL Server column definition is using nchar() instead of nvarchar().

The former forces trailing spaces up to the defined length of the field.  

The latter  just stores the data as provided to the database, without adding any trailing spaces to fill up to the stated length

This certainly appears to be the case with some of my columns! Now I have to look at a method to convery nchar to nvarchar :)

Cheers!

Change your db column definition to nvarchar and then do something like:

UPDATE <your_table> SET <your_column> = rtrim(ltrim(<your_column>))

Leave a Reply