0
var value = document.getElementById("height_"+ rowCount).value;
value = value .replace("a", "");
document.getElementById("height_"+rowCount).value = value;

Above is a javascript example that I used to replace the letter "a" in my text field height_row e.g height_1 (for row 1)

I want to able to filter all input except

0 to 9, letter s, how do I auto replace all input with blank if its not number 0 to 9 or letter "s"

Thanks for helping

1

1 Answer 1

2

Use a regular expression:

var rowCount = 1;

var value = document.getElementById("height_"+ rowCount).value;
value = value.replace(/[^0-9s]/g, "");
document.getElementById("height_"+rowCount).value = value;
<input type="text" value="one 1 two 2 three 3 numbers" id="height_1" />

Sign up to request clarification or add additional context in comments.

2 Comments

How do we modify the code such that when the textfield will replace all the char that doesn't match the "pattern" instantly after a letter is type
That's a different question. See, for example: stackoverflow.com/questions/6763012/…

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.