Reputation: 1978
I want to write a regular expression for a mobile number
9042248903
I tried using the below expression
^\d+([\.\,][0]{2})?$
^[0-9]+$
Upvotes: 0
Views: 71
Reputation: 54
try this
"[1-9][0-9]{9,14}"
if(!teststring.matches("[1-9][0-9]{9,14}")) {
// blah! blah! blah!
}
Upvotes: 1
Reputation: 881683
Those specifications can be met with
^[0-9]{10,15}$
The start and end markers ^$
ensure there's nothing on either side.
[0-9]
gives you a digit.
{10,15}
meannse ten to fifteen occurrences of that digit speciffication.
Upvotes: 3