Mobile Number Validation In LWUIT

853 Views Asked by At

I want to check the 10 digit phone number whether all 10 digits are same or different. If same means Invalid mobile number alert will be displayed. I want a code in LWUIT.

1

There are 1 best solutions below

3
On

set the TextField max size to 10. It allows only 10 digits. Also set the numeric constraint to that TextField. It allows only numeric value. See the sample code,

TextField txtf = new TextField();
txtf.setConstraint(TextField.NUMERIC);
txtf.setInputModeOrder(new String[] {"123"});
txtf.setMaxSize(10);
form.addComponent(txtf);

Also check the length of the text in TextField. If length isn't 10 digit, you can showing the alert.

For checking repeated numbers, Use addDataChangeListener. You can handle the validation inside of this listener.