Vaelyr Vaelyr - 17 days ago 7
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) {
NumberSequence.save({"type": form.$name}, form.$data,
success(result),
error(form, result));
}


Data here contains 3 fields:


  • start

  • end

  • number



I would need to filter all of them.

Any suggestions?

Answer

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.

Comments