java - Validation of mobile number field -
i want know what's wrong code? taking input in textbox(a 10-digit mobile number). problem that, code time prints else statement if input correct.
mobno=textmobno.gettext(); textmobno.addfocuslistener(new focuslistener() { @override public void focuslost(focusevent arg0) { // todo auto-generated method stub pattern pattern = pattern.compile("^[789]\\d{9}$"); matcher matcher = pattern.matcher(mobno); if (matcher.matches()){ system.out.println("valid"); } else{ system.out.println("invalid"); } } @override public void focusgained(focusevent arg0) { // todo auto-generated method stub }; });
you obtaining text text field, adding focuslistener. @ later time, focus listener fired, uses text got field before focus listener active. yeah, text before typed in field; explain being empty string. try getting text in focus listener... (hint - string text field not continually updated text typed in field...)
Comments
Post a Comment