Mobile Number Validation In LWUIT [closed]

2019-09-24 04:48发布

问题:

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:

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.