Allow Only Numbers in Input Field HTML Regex

Hey, if you are a Frontend, Backend or Full Stack Developer and you want to allow any input field to accept only number values to take then you can use regex in the HTML input tags.

But sometimes when developers add input fields dynamically they face this issue they apply different regex to make input fields to allow only numbers but they fail.

So I found a solution for you that you can use to allow your dynamically added input to allow only number values. So try the given code below and let me know does it works or not or do you found any new errors?

HTML Regex to Accept Only Numbers

oninput="this.value = this.value.replace(/[^0-9]/g, '')"

Example of HTML Input Regex Only Numbers 

<input type="text" name="numValue" id="numValueInput" oninput="this.value = this.value.replace(/[^0-9]/g, '')">

complete html notes pdf, complete html notes for beginners, geeks help html css projects,

Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad

Ads Section