Varun Sridharan
Varun Sridharan

Reputation: 1978

Regular expression for a mobile number

I want to write a regular expression for a mobile number

  1. The field should not be empty
  2. Should be minimum of 10 - 15 char
  3. The field should contain only number eg : 9042248903

I tried using the below expression

^\d+([\.\,][0]{2})?$
^[0-9]+$

Upvotes: 0

Views: 71

Answers (4)

AkshayP
AkshayP

Reputation: 2169

Try this

^[0-9]{10,15}$

Demo with Explanation

Explanation

Upvotes: 0

Milan Mendpara
Milan Mendpara

Reputation: 3131

This will work too!

/^\d{10,15}$/

Upvotes: 2

Silent Coder
Silent Coder

Reputation: 54

try this 

"[1-9][0-9]{9,14}"

if(!teststring.matches("[1-9][0-9]{9,14}")) {
    // blah! blah! blah!
}

Upvotes: 1

paxdiablo
paxdiablo

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

Related Questions