Vaelyr Vaelyr - 1 year ago 79
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download