# Number input field (stuck with whitespaces)

**URL:** <https://www.ruby-forum.com/t/number-input-field-stuck-with-whitespaces/105676>\
**Category:** Rails\
**Created:** [June 1, 2007, 9:50am UTC](https://www.ruby-forum.com/t/number-input-field-stuck-with-whitespaces/105676 "2007-06-01T09:50:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dusan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@Dusan](https://www.ruby-forum.com/u/Dusan)\
**Post date:** [June 1, 2007, 9:50am UTC](https://www.ruby-forum.com/t/number-input-field-stuck-with-whitespaces/105676/1 "2007-06-01T09:50:17Z")

</div>

All,

I am RoR newbee, so maybe this is stupid question, but I can’t figure  
it out. I have a form from which I want to get some numbers. But if  
user has typed a number with whitespaces in it, I am getting only the  
first part until the whitespace.

For example, if user types 300 000, the record is saved as only 300.

Can anybody help?

---

<div class="post-metadata">

**Author:** ![Dusan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@Dusan](https://www.ruby-forum.com/u/Dusan)\
**Post date:** [June 1, 2007, 2:23pm UTC](https://www.ruby-forum.com/t/number-input-field-stuck-with-whitespaces/105676/2 "2007-06-01T14:23:56Z")

</div>

There’s probably a better way to do this but here is one suggestion.  
Instead of putting the return from the form into the (I presume  
numerical) model method, create a dummy method which gets the input from  
the form and puts it into a string. Then convert it yourself to a  
number.

number = string\_from\_form.gsub(/\s+/, “”).to\_i
