java - Checking for valid mobile number in android -
i making registration application in android. want trap invalid mobile numbers entered in edittext box. once click submit button, app check if mobile number entered valid.
all valid number should start "639"
. question how going read first 3 digits user entered? example, user enters 639158716271
, valid number. while 197837281919
invalid.
can suggest how accomplish this?
thanks in advance!
//get string edit text by: string number = youredittext.gettext().tostring(); if(number != null && number.matches("639[0-9]{9}")) //do need valid input else //do need invalid input
matches()
ensures entire string cooresponds (exactly) regular expression takes. 639[0-9]{9}
says string must start off 639 , followed 9 digits (0-9). if wanted match "639"
followed 7 9 numbers, example, use: 639[0-9]{7,9}
. regular expressions: http://docs.oracle.com/javase/tutorial/essential/regex/
Comments
Post a Comment