Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanted to get the mobile number from the user in java using scanner. When the user enters the number, he/she shouldn't be able to enter when the limit exceeds 10. Could anyone share how ?


What I have tried:

long mobNo;
     Scanner s=new Scanner(System.in);
     mobNo=s.nextLong();
      int length = (int)(Math.log10(mobNo)+1);
     if(length==10)
         System.out.println("Successfully entered !");
     else
         System.out.println("Enter only 10 digits");
Posted
Updated 15-Jun-18 5:52am
v2

1 solution

Regular Expressions- there are many available patterns depending on localized formats
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900