0

Kindly help me out for below requirement.

  1. Replace non-numeric from input
  2. but allow only one digit for floating constants.

Here is my requirement

var a = "$150.00"

Now when user tab out on this input value; it should remain as it is. But it is getting as $15000

This is regex I am using.

this.value.split('').reverse().join('').replace(/[\D]/i,'').split('').reverse().join('');

Validation is happening on keydown event.

1 Answer 1

2

Add an optional period into the regex.

this.value.split('').reverse().join('').replace(/[\D]\.?[\D]/i,'').split('').reverse().join('');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.