How about this?  It's only called when the user leaves the field.  The
replace uses a regular expression, the part between the forward
slashes.  The \s means "space", the + means one or more of the
preceding, and the $ means match only at the end of the string.


$(document).ready(function(){
            $("#couponCode").blur(function (e){
                $("#couponCode").val($(this).val().toUpperCase());
                $("#couponCode").val($(this).val().replace(/\s+
$/,''));
            });
        });

Reply via email to