user723217
user723217

Reputation: 153

jQuery .numeric and pasting content

The .numeric function (http://www.texotela.co.uk/code/jquery/numeric/) works great, but when you paste content into the txtOrderName field and you exit the field it doesnt validate.

Does anyone know any modifications that will allow the .numeric function to be run again after content has been pasted?

For example, if I paste '4,00' into the txtOrderPrice field, I dont want the comma (,) to be displayed. The numeric function ignores this if you type '4,00' in the field (changes to '400'). But knowing people they might just paste '4,00' into the field and stuff things up.

<script type="text/javascript" src="jquery.numeric.js"></script>
  $(document).ready(function() {    
    $(".numeric").numeric();
  });
</script>

<input class="numeric" type="text" id="txtOrderPrice" name="txtOrderPrice_name" maxlength="128" />

Upvotes: 0

Views: 1940

Answers (2)

kasper Taeymans
kasper Taeymans

Reputation: 7026

You could replace the , with a . like so:

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

Upvotes: 0

Ruslan
Ruslan

Reputation: 10147

it says it's the limitation:

Limitations / Bugs CTRL+A does not select all text. Text pasted via the mouse is not auto-corrected, though a callback can be defined to work around this.

so, the workaround would be to hook it up to either .blur() or .focusout() event:

$(document).ready(function() {
    $(".numeric").numeric();
    $(".numeric").focusout(function() {
        $(this).keyup();
    });
})

http://jsfiddle.net/xFJfP/

Upvotes: 2

Related Questions