Vaelyr Vaelyr - 4 months ago 26
Javascript Question

Strip whitespace from fields before Angular post request

I need to strip all whitespace from three fields (leading, trailing and between characters) that will be sent to the backend by Angular post request. Data is passed from the form data object. Currently I have solved it by creating custom deserializer for Jackson that does the job, but I would be more interested to remove them before they reach my Spring backend.

function insertNumber(form, result) {{"type": form.$name}, form.$data,
error(form, result));

Data here contains 3 fields:

  • start

  • end

  • number

I would need to filter all of them.

Any suggestions?


AngularJS provides an ng-trim directive for doing this see the input directive documentation. If this isn't what you were looking for, then using a regular expression as suggested by @KyleK.