简体   繁体   中英

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]+$

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.

这也可以!

/^\d{10,15}$/
try this 

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

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

Try this

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

Demo with Explanation

Explanation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM