Free programming examples and instructions

Regular expression number only

Regular expression for integers(Number only), How to write regular expressions for number only text

by Athil

Posted on 28 Nov 2016 Category: Javascript Views: 1057

Edited on 02 Jun 2017

Hi, If we want to create a number only text box we can use the expression

/^[0-9]*$/             //Number only with no limit

Here we can see a '*' almost end of the expression and why I give '*' means it have no limit. That is we can create any length of text that accept number only.[0-9] Means accept all characters between 0-9

/^[0-9]{10}$/              // It accepts only 10 digits 

If you want to add more digits change the value from braces ({}) to other value.

/^[0-9]{10,20}$/        //Accepts any digits of numbers between 10 - 20 digits

Leave a Comment:


Maksoom Rasi Thursday,30 Mar 2017

Thnx bro...