0

With form submitting, users will enter information such as first name, last name, age, etc... here is the code to grab that information

var fn = $("#first_name").val();

I want to make sure whatever is stored in fn doesn't contain any spaces, such that if a user enters a first name followed by a space, or presses the space by and then types their first name, it needs to be removed. I have tried .trim() and strg.replace(/\s+/g, ' '); but these do not work.

I do not know or code in javascript/jquery so I don't know much about it, I just know I need to fix it. Thanks for anyone who can provide some help!

John Doe
  • 1
  • 1
  • Possible duplicate of [Replacing all occurrences of a string in JavaScript](http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript) – Finrod Feb 29 '16 at 16:21
  • 1
    `var fn = $("#first_name").val().trim();` doesn't work??? – A. Wolff Feb 29 '16 at 16:24
  • You are doing something wrong. Provide sample replicating your issue – A. Wolff Feb 29 '16 at 16:52
  • Here is the code used to grab the string from the webpage, same as above: `var fn = $("#first_name").val().trim();` in javascript- From here, that information gets passed to here `first_name = params.get('first_name','')` in python- Using breakpoints, the first_name variable comes back with the whitespaces – John Doe Feb 29 '16 at 17:03
  • Also want to say, when using console.log() to print the variable to the console, using google chrome, it comes back trimmed. The variable does get trimmed, however the trimmed variable is not being passed. – John Doe Feb 29 '16 at 17:15

0 Answers0