FCSAmerica / angular-fcsa-number

An Angular directive that validates numbers and adds commas as thousand separators.
Apache License 2.0
83 stars 58 forks source link

Prevent Invalid Character Entry - Copy and Paste #10

Open mblasiusnyc opened 9 years ago

mblasiusnyc commented 9 years ago

Currently, you can still paste invalid characters into an input box when "preventInvalidInput: true".

paulyoder commented 9 years ago

preventInvalidInput uses the keyPress event to prevent entering invalid input. After each keyPress it confirms the current key that was pressed is valid. It doesn't look at the whole value for the input box. That's why pasting in a value bypasses the prevention.

I really don't want to check the whole input value every time a key is pressed because performing regex matches can get quite expensive. If you really want to prevent the user from pasting invalid input, then I recommend creating another directive that does it and apply it to the input box.