user2498634
user2498634

Reputation: 51

Simple number validation using regular expression

I am new to regular expression. I need to validate the following using regular expression:

Upvotes: 1

Views: 10193

Answers (2)

thefourtheye
thefourtheye

Reputation: 239693

You can use the following RegEx, \\d{6,10}. This would match any string which has only digits and the number of times digits can occur is 6 to 10.

(By digit we mean any character with the Unicode General Category of Nd (Number, Decimal Digit.) as Java uses the ICU Regular Expressions libraries.)

You can see how the RegEx works here

    String pattern = "\\d{6,10}", myString = "111111";
    System.out.println(myString.matches(pattern));

would print

true

Upvotes: 7

CodeIsLife
CodeIsLife

Reputation: 1255

you can use this code

[0-9]{6, 10}

or

\d{6, 10}

enjoy !

Upvotes: 2

Related Questions