Delete white spaces in textbox when copy pasted with jquery

I've a textbox of order id(7 digits), which in normal cases you copy paste from email to the textbox, many times you accidently copy one or two white spaces which causing annoying validation error.

I want jquery code in my Layout\MasterPage that does't allow writing white spaces and when copy paste (with keyboard or mouse) numbers with white spaces removes the spaces and keeps the numbers only.

The above should happen only on textboxes with class white-space-is-dead

Answers


Do

$('.white-space-is-dead').change(function() {   
    $(this).val($(this).val().replace(/\s/g,""));
});

Updated copy of your fiddle.

Note that \s may be more than you like. If so, use a literal white space instead

.replace(/ /g,""));


Need Your Help

Allow only triggers to update a column

sql postgresql triggers privileges

I have two tables, t1(foo) and t2(bar), and a trigger on update t2.bar that updates t1.foo to something else.

some JavaScript variables missing in scope

javascript scope closures

The problem I am having is that I am trying to access variables that I believe should be in scope but they are not. I am using Underscore.js to loop through arrays and add up values, in the example...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.